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 ...
You can use IntelliJ plugin
JS GraphQL
then IDEA will ask you create two files "graphql.config.json" and "graphql.schema.json"Then you can edit "graphql.config.json" to point to your local or remote GraphQL server:
After that IDEA plugin will auto load schema from GraphQL server and show the schema json in the console like this:
You can download a remote GraphQL server's schema with the following command. When the command succeeds, you should see a new file named
schema.json
in the current working directory.~$ npx apollo-cli download-schema $GRAPHQL_URL --output schema.json
You can use GraphQL-JS's introspection query to get everything you'd like to know about the schema:
If you want just the information for types, you can use this:
Which uses the following fragment from the introspection query:
If that seems complicated, it's because fields can be arbitrarility deeply wrapped in nonNulls and Lists, which means that technically even the query above does not reflect the full schema if your fields are wrapped in more than 7 layers (which probably isn't the case).
You can see the source code for introspectionQuery here.