The Schema Definition Language of GraphQL is used to define the schema of data for a GraphQL based API.
Being platform/language agnostic, GraphQL uses it's own language to define and query a GraphQL API, and when you're building the backend, you'll define your schema with SDL.
Here's a quick round down of this list:
- Scalar Types
- Object Types
- Query Type
- Mutation Type
- Input Types
- Enum Types
So let's start with the simplest type, the Scalars.
Scalar types are like the Primitive types in your favorite language (i.e. strings, booleans, floats, etc.).
In GraphQL, we also have these types which we call Scalars:
- ID - this one serializes to string, so it's safe to say that id's are string
It holds a key-value pair, where keys are called as fields, and each field defines the types of data they return, which can be either a Scalar or another Object (to emphasize relationships among nodes).
Here's an example of an object in GraphQL:
This type is the entry point for the "GET" request (so to speak). It is consistent to call this type Query. Each field in the Query Type defines the type of data that each field will return.
Here's an example of a Query type:
This is near identical to Query type, but is responsible for the Writes of the API. You use it for "CREATE", "UPDATE", and "DELETE".
Like Query, Mutation type is also named consistently that way, Mutation.
Here's an example of a Mutation type:
Since the arguments of a field on other types can be lengthy, it will be tricky and hard to understand it if it got too long. And this is the purpose of Input Types.
Input types are special objects which you can pass as argument to an input in a field, just like how I did it on the example above.
Here's an example of an input type:
The Enum types are special types since you can create your own type outside the primitive data types.
This type will be more useful for a specified options of values that a field or endpoint can accept as argument or return. An Enum can be placed wherever a Scalar is allowed.
Just to be clear, Enum serializes into strings.
Here's an example of an Enum Type: