How to make introspection from an endpoint file with apollo 2? - graphql

with apollo 1.9.2 I'm used to make introspection of the graphql schema using a file as endpoint (that way the server does not need to run).
Here the 1.9 command:
apollo schema:download --endpoint ./schema/def/app.graphql ./schema/lib/schema.json
then thanks to the generated json file I can generate the types that will be used in the client and server code:
apollo codegen:generate --queries ./schema/*.graphql --schema ./schema/lib/schema.json
Now with apollo 2, the apollo schema:download command, renamed apollo service:download, supports only an url. If I do not have that types the server can not start. chicken & eggs issue.
I did not find in the doc how to do that now.
thanks for your help.

I got the answer on gitHub
I must use a config file apollo.config.js with the following
module.exports = {
service: {
localSchemaFile: './path/to/schema.graphql',
},
};
then call
apollo service:download -c ./path/to/apollo.config.js ./schema/lib/schema.json

Related

How can I create a query on the FaunaDb cli?

I am trying to create a query on the Fauna DB command line interface.
I have a collection and if I run
Map(Paginate(Documents(Collection('users'))), Lambda(x => Get(x)))
I get
data: [
{
ref: Ref(Collection("users"), "350926483869401600"),
ts: 1670928424920000,
data: {
username: 'jeff',
login_id: '123621b8-d6fc-465e-90ae-dca8d83e3321'
}
}
]
This page suggests that I can write a query thus
{users{username}}
But when I attempt it the cli hangs on the ... prompt
If I try
{
users
{
username
}
}
it returns
Uncaught ReferenceError: users is not defined
What am I doing wrong?
The page you link to is the general documentation for GraphQL, which is independent of Fauna.
The Fauna CLI is not a GraphQL client. The shell command lets you query your databases with FQL. The online shell in the customer Dashboard is the same. Both the CLI shell and online shell use the Javascript FQL drivers, so the shell is treating your input like javascript and throwing an error because there is no users variable.
To use GraphQL with Fauna, you must first upload a GraphQL schema through the Dashboard (Check out our GraphQL quick-start tutorial), or using the CLI upload-graphql-schema command, or even directly with an HTTP request.
Once you have uploaded a GraphQL schema, Fauna will host a GraphQL API that you can query through the playground in the Dashboard, or use your preferred GraphQL client.

Export / finding GraphQL Schema with Strapi and GraphQL plugin

I’m new to Strapi and to GraphQL.
I successfully created a website that uses Apollo to query data from my Strapi website.
So functionally I have everything I need.
For my DX I’m wondering:
Since I installed the GraphQL IntelliJ plugin: Where do I find the schemas for it? I read something about remote schema detection - is that supported with Strapi GraphQL Plugin? Where can I read about it? Otherwise how can I export GraphQL schema files from Strapi?
If I got 1) to work: Will TypeScript types work out of the box? Would I use one of the GraphQL schema to TS converters out there? It feels like there might be something working automatically, but I can’t tell till I get 1) to work.
First, you asked two separate questions and should therefore separate then in two separate threads.
To answer your first question: Here is how you can utilise the GraphQL IntelliJ plugin:
You need to create a .graphlconfig file. In Webstorm select your project folder and go to 'File' -> 'New' -> 'GraphQl Configuration File'.
Change the endpoint url to your strapi endpoint.
Visit the GraphQl Tool Window, double click your endpoint and select 'Get GraphQl Schema from Endpoint (introspection)'. This will retrieve the schema file from strapi and save it to schema.graphql.
Now you can run queries against your endpoint, e.g. create a new Scratch File scratch.graphql and run queries against your endpoint or try to figure out how to solve your second question ;)
Thank you for the answer! This was helpful!
Further to this, one query - typically, is .graphlconfig committed to git repo and scratch.graphql ignored from the git repo?
In addition for others looking for a similar solution - you could use values from .env. using the format below:
{
"name": "Strapi GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "${env:GRAPHQL_HOST}/graphql",
"headers": {
"Authorization": "Bearer ${env:GRAPHQL_TOKEN}",
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}

How can I add a share to GraphQL Bin option to my Apollo server playground?

I am using Apollo server to implement a GraphQL API, which automatically gives me a GraphQL Playground. According to the GraphQL Playground docs I should have (or at least be able to enable) a "Share" feature that will create a GraphQL Bin link (e.g. https://graphqlbin.com/OksD) that I could send to a colleague so they can view and run my same query.
Unfortunately this isn't available from Apollo server out of the box. How can I enable this feature? If this is not possible, is there another simple way for me to export my query from GraphQL Playground for someone else to import it? (I see the "copy curl" option, but I don't see an easy way to import from curl.)
Add shareEnabled: true to your playground options, e.g.
const apolloServer = new ApolloServer({
schema,
debug: isDevelopment,
introspection: isDevelopment,
playground: {
shareEnabled: true,
},
});
You might also want to fix CORS origin headers, allowing requests from https://graphqlbin.com

How to test graphql + apollo server for upload file mutation using postman?

I using apollo server, and have this mutation :
mutation {
updateData(
file1: fileOne,
file2: fileTwo,
file3: fileThree,
payload: {
id: "7e3583b4-5673-48df-a3cf-44a4ec33f0e1"
}
){
isSuccess
error
data
}
}
I want to test it using postman, because i didnt find any clue test it using graphql playground.
I already find how to test graphql from postman, but it doesn't contains information about file upload. graphql postman
I have an idea from apollo-upload-client to post using multipart-formdata but it still fail.
please help how to test graphql with apollo server for upload file mutation using postman?
thanks
I need to understand about how file upload works in node js (because I use nodejs ini this case)
I install multer for file upload middleware using nodejs and expressjs, if you use other framework or programming language, just try adjust it
In postman I use formdata
you can find the good step by step here
Upload file graphql using postman

How to change websocket url in graphql-playground (subscriptions)

I wanted to change the graphql websocket end point inside graphql, anyone know how to do this?
by default it pings
wss://localhost/graphql
I need to change it to pusher url
thanks :-)
If you are running a standalone instance of GraphQL Playground, the URL is passed directly to the component as a prop:
<Playground
endpoint="http://localhost/graphql"
subscriptionEndpoint="wss://localhost/graphql"
/>
If you're using apollo-server, the endpoint URL should be derived from the subscriptionsPath, but it can also be set directly in the config:
const server = new ApolloServer({
typeDefs,
resolvers,
playground: {
subscriptionEndpoint: 'wss://localhost/graphql',
},
});
EDIT:
It doesn't appear there's a way to configure the desktop client with a specific subscription URL, unless you're using it with a local repo that contains a .graphqlconfig. In that case, you can provide additional information about your environment, including the subscription url, in the config file as outlined here.

Resources