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 ...
using apollo cli
You could use
apollo codegen:client
. See https://github.com/apollographql/apollo-tooling#apollo-clientcodegen-outputThis is the query that GraphiQL uses (network capture):
Refer to https://stackoverflow.com/a/42010467/10189759
Would like to point out that if authentications are needed, that you probably cannot just use the config file generated from
graphql init
You might have to do something like this, for example, using the github graphql API
If you want to do it by your self, read these code:
There is a modular state-of-art tool 「graphql-cli」, consider looking at it. It uses package 「graphql」's buildClientSchema to build IDL .graphql file from introspection data.
Update
Using
graphql-cli
is now the recommended workflow to get and update your schema.The following commands will get you started:
You can even listen for schema changes and continuously update your schema by running:
The easiest way to get a GraphQL schema is using the CLI tool get-graphql-schema.
You can install it via NPM:
There are two ways to get your schema. 1) GraphQL IDL format or 2) JSON introspection query format.
GraphQL IDL format
JSON introspection format
or
For more information you can refer to the following tutorial: How to download the GraphQL IDL Schema