The core building block of GraphQL is its schema. It is used as a middle way between server and client while defining the accessibility of the data.
A GraphQL schema is written in Schema Definition Language (SDL) and refers to the exact mutations and queries that a client can execute against your data graph. It can be built with any programming language.
In other words, the schema defines the type of data that can be fetched, the relationships between these types of data, and what type of queries are allowed. The most basic components of a GraphQL schema are object types. They represent a kind of object you can fetch from your service along with its associated fields. In addition, the schema helps the client validate their query and eliminate unavailable data or the wrong structure stage.
The GraphQL query language is strongly typed. Due to its strong type system, GraphQL gives you the ability to query and understand the underlying schema using Introspection.
The Introspection feature allows you to query the schema and discover the available queries, mutations, subscriptions, types and fields in a specific GraphQL API.
The schema acts as a contract between the frontend and backend, improving the communication between them. Introspection requests information about what queries the schema supports.
A server exposes the following introspection queries on the Query operation type:
__schema
__type
__typename
Note that introspection queries start with __
.
There are scenarios where you might want to see all the available queries in a GraphQL API. You can query the schema as follows:
{__schema {queryType {fields {namedescription}}}}
The above query returns the name and description of all the available queries.
You can also fetch all the available mutations with the following query:
{__schema {mutationType {fields {namedescription}}}}
Similar to the first query, it returns the name and description of all available mutations.
Lastly, you can fetch all types as follows:
{__schema {types {namedescription}}}
This way, you can see all the types available in the GraphQL API. Similarly, you can retrieve all the available directives and subscriptions.
This guide cannot cover all the details about the GraphQL schema. Here are some starting points to help you find more details: