Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get GraphQL whole schema query

Tags:

schema

graphql

I want to get the schema from the server. I can get all entities with the types but I'm unable to get the properties.

Getting all types:

query {   __schema {     queryType {       fields {         name         type {           kind           ofType {             kind             name           }         }       }     }   } } 

How to get the properties for type:

__type(name: "Person") {     kind     name     fields {       name       type {         kind         name         description       }     }   } 

How can I get all types with the properties in only 1 request? Or ever better: How can I get the whole schema with the mutators, enums, types ...

like image 537
Aleksandrenko Avatar asked May 23 '16 18:05

Aleksandrenko


People also ask

How do I get a full schema in GraphQL?

How To Get The Schema — Introspection Queries. Some GraphQL servers don't provide a convenient GraphQL API explorer. Instead, to get the schema we need to send a HTTP request to the GraphQL server endpoint asking for the GraphQL schema. This type of HTTP request is called a GraphQL introspection query.

Where is the GraphQL schema?

A GraphQL schema is at the core of any GraphQL server implementation. It describes the functionality available to the client applications that connect to it.


2 Answers

Update

Using graphql-cli is now the recommended workflow to get and update your schema.

The following commands will get you started:

# install via NPM npm install -g graphql-cli  # Setup your .graphqlconfig file (configure endpoints + schema path) graphql init  # Download the schema from the server graphql get-schema 

You can even listen for schema changes and continuously update your schema by running:

graphql get-schema --watch 

In case you just want to download the GraphQL schema, use the following approach:

The easiest way to get a GraphQL schema is using the CLI tool get-graphql-schema.

You can install it via NPM:

npm install -g get-graphql-schema 

There are two ways to get your schema. 1) GraphQL IDL format or 2) JSON introspection query format.

GraphQL IDL format

get-graphql-schema ENDPOINT_URL > schema.graphql 

JSON introspection format

get-graphql-schema ENDPOINT_URL --json > schema.json 

or

get-graphql-schema ENDPOINT_URL -j > schema.json 

For more information you can refer to the following tutorial: How to download the GraphQL IDL Schema

like image 155
schickling Avatar answered Sep 28 '22 02:09

schickling


This is the query that GraphiQL uses (network capture):

query IntrospectionQuery {   __schema {     queryType {       name     }     mutationType {       name     }     subscriptionType {       name     }     types {       ...FullType     }     directives {       name       description       locations       args {         ...InputValue       }     }   } }  fragment FullType on __Type {   kind   name   description   fields(includeDeprecated: true) {     name     description     args {       ...InputValue     }     type {       ...TypeRef     }     isDeprecated     deprecationReason   }   inputFields {     ...InputValue   }   interfaces {     ...TypeRef   }   enumValues(includeDeprecated: true) {     name     description     isDeprecated     deprecationReason   }   possibleTypes {     ...TypeRef   } }  fragment InputValue on __InputValue {   name   description   type {     ...TypeRef   }   defaultValue }  fragment TypeRef on __Type {   kind   name   ofType {     kind     name     ofType {       kind       name       ofType {         kind         name         ofType {           kind           name           ofType {             kind             name             ofType {               kind               name               ofType {                 kind                 name               }             }           }         }       }     }   } } 
like image 41
James Carnegie Avatar answered Sep 28 '22 03:09

James Carnegie