Printing Schema
The GraphQL Schema file is the core document that defines the data structure and operations of the GraphQL API. It uses the GraphQL Schema Definition Language (SDL) to describe information such as data types, fields, queries, mutations, and subscriptions. It serves as the basis for server-side request processing and also provides an interface document for the client, helping developers understand the available data and operations.
Generating files from Schema
We can use the printSchema
function from the graphql
package to print out the Schema.
The above code generates a schema.graphql
file that contains all the contents of the Schema.
Using GraphQL Schema
GraphQL Schema can be used for many purposes, common uses include:
-
Merging Schema from multiple microservices into a supergraph for unified cross-service querying on the client side. This architecture is called federation.
-
Developed and type-checked on the client side using code generation.
-
Integrate with TypeScript for client-side development for better type checking and auto-completion during development, see gql.tada for more information.