Export / finding GraphQL Schema with Strapi and GraphQL plugin - graphql

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
}
}
}
}

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.

How to setup ArangoDB replication via the ArangoDB Go driver

I need to set up a simple replication schema with a secondary database. I figured out that using arangosh I can set it up with the following commands:
db._useDatabase("myDB");
require("#arangodb/replication").setupReplication({
endpoint: "tcp://main-server:8529",
username: "user",
password: "pass",
verbose: false,
includeSystem: false,
incremental: true,
autoResync: false,
autoStart: true,
restrictType: "include",
restrictCollections: [ "Products" ]
});
This setup, however does not seem to persist. Connection going down, or server restarts make it disappear.
So, I would like to set up some monitoring and re-establishment of the replication in my Go program.
I searched both the ArangoDB website Manual pages, and Go driver documentation but I could not find anything that would allow me to run the above setup in Go using the driver.
Additionally, I didn't find how I could interface with arangosh, and possibly run the JS code above and get the results. Is that possible somehow using the Go driver?
I accidentally found a solution to this.
The Golang driver does not provide this functionality. But Arango has a pretty simple HTTP based API which allows access to all functions and features of the database engine.
Here's the link to the documentation I used: https://www.arangodb.com/docs/3.8/http/index.html
(I'm using version 3.8 because after that the type of replication I needed was no longer part of the community edition).
Setting up a replication requires just two steps:
PUT request to the /_db/yourDBname/_api/replication/applier-config with a JSON payload:
{
"endpoint":"tcp://serverIP:8529",
"database":"yourDBname",
"username":"root",
"password":"password",
"autoResync": true,
"autostart":true
}
And another PUT request to get the replication actually started, to /_db/yourDBname/_api/replication/applier-start . This one doesn't need any payload
And to see how things are going you can do a GET request to /_db/yourDBname/_api/replication/applier-state
All these requests need a JWT token that you can get with a POST request to /_open/auth with a payload of:
{
"username": "user",
"password": "passwd"
}
The token you receive will need to be included in the HTTP header as a bearer token. Pretty simple.

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 make introspection from an endpoint file with apollo 2?

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

Resources