Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate schema.json with GraphiQL or GraphQL endpoint

I'm having issues creating a schema.json file that can be parsed with babel-relay-plugin without running into an error. Taking a look at the schema.json file included in relay's example folder, I tried to copy the query in GraphiQL but I can't seem to get it right. I'm using Laravel as the backend. Is this something I can accomplish through GraphiQL or sending a request to the GraphQL endpoint and saving the response?

The error occurring when attempting to parse the schema.json file:

Cannot read property 'reduce' of undefined while parsing file: /Users/username/Sites/Homestead/Code/ineedmg-graphql/resources/assets/js/app.js

Last attempt using GraphiQL:

{
  __schema {
    queryType { 
      name
    },
    types {
        kind,
        name,
        description,
        fields {
            name,
            description,
            type {
              name,
              kind,
              ofType {
                name
                description
              }
            }
            isDeprecated,
            deprecationReason,
        },
      inputFields {
        name
        description
      }
      interfaces {
        kind
        name
        description
      },
      enumValues {
        name
        description
        isDeprecated
        deprecationReason
      }
    },
    mutationType { 
      name
    },
    directives {
      name,
      description,
      onOperation,
      onFragment,
      onField,
      args {
        name
        description
        defaultValue
      }
    }
  }
}
like image 349
csm232s Avatar asked Nov 03 '15 21:11

csm232s


1 Answers

Yup! If you take a look at the examples, you can see that they generate the schema.json file by executing a query: https://github.com/relayjs/relay-starter-kit/blob/84da9351d100f97e6ed4f08bc70a893779e61c29/scripts/updateSchema.js#L11

This query is in fact just this specific query from graphql-js: https://github.com/graphql/graphql-js/blob/v0.4.12/src/utilities/introspectionQuery.js#L11-L89.

like image 159
taion Avatar answered Oct 01 '22 17:10

taion