fancy
fancy

Reputation: 2149

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:

  1. 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?

  2. 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.

Upvotes: 2

Views: 2119

Answers (2)

Shrikant Shet
Shrikant Shet

Reputation: 21

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

Upvotes: 0

Ali
Ali

Reputation: 836

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:

  1. You need to create a .graphlconfig file. In Webstorm select your project folder and go to 'File' -> 'New' -> 'GraphQl Configuration File'. Create new Graphql Configuration File

  2. Change the endpoint url to your strapi endpoint. Adjust endpoint url

  3. 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. Get GraphQl Schema from Endpoint (introspection)

  4. 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 ;)

Upvotes: 3

Related Questions