title | code |
---|---|
Defining a GraphQL schema |
The core of a GraphQL server is its schema - this is a representation of the data available. The default API for graphql-js uses constructors to create object types, but using a package called graphql-tools, you can instead write the schema using the GraphQL type language.
Every GraphQL schema needs a Query type - that defines the entry point to the whole API. Here you can see that when we query the server, we can initially ask for the feed, a specific entry, or the currentUser.
Query type is for reading data - when we want to write data, we need a Mutation type. Here you can see that the possible data writes in this app are submitRepository, vote, and submitComment.
Obviously, we can't put the whole schema of the API in just one file, so this one represents the core root fields. We import the rest from another file and merge them together, as seen here.
Let's move on and look at one of the more specific schema files.