GraphQL’s Schema Definition Language (SDL) types

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 de…


This content originally appeared on DEV Community and was authored by Menard Maranan

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.

Supported Types

Here's a quick round down of this list:

  1. Scalar Types
  2. Object Types
  3. Query Type
  4. Mutation Type
  5. Input Types
  6. Enum Types

So let's start with the simplest type, the Scalars.

1.Scalar Types

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:

  • Int
  • Float
  • String
  • Boolean
  • ID - this one serializes to string, so it's safe to say that id's are string

2.Object Types

I like to think of it as a JavaScript object (but defined as it's own type) or a class, as in the class in OOP (Object Oriented Programming).

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:

GraphQL object types

3.Query Type

This type is the entry point for the "GET" request (so to speak). It is consistent to call this type Query. Each fields in the Query Type defines the type of data that each field will return.

Here's an example of a Query type:

GraphQL Query Type

4.Mutation 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:

GraphQL mutation type

5.Input Types

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:

GraphQL Input type

6.Enum Types

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:

GraphQL Enum Types

Follow Me on Twitter!

Twitter @menard_codes


This content originally appeared on DEV Community and was authored by Menard Maranan


Print Share Comment Cite Upload Translate Updates
APA

Menard Maranan | Sciencx (2021-06-24T09:49:13+00:00) GraphQL’s Schema Definition Language (SDL) types. Retrieved from https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/

MLA
" » GraphQL’s Schema Definition Language (SDL) types." Menard Maranan | Sciencx - Thursday June 24, 2021, https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/
HARVARD
Menard Maranan | Sciencx Thursday June 24, 2021 » GraphQL’s Schema Definition Language (SDL) types., viewed ,<https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/>
VANCOUVER
Menard Maranan | Sciencx - » GraphQL’s Schema Definition Language (SDL) types. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/
CHICAGO
" » GraphQL’s Schema Definition Language (SDL) types." Menard Maranan | Sciencx - Accessed . https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/
IEEE
" » GraphQL’s Schema Definition Language (SDL) types." Menard Maranan | Sciencx [Online]. Available: https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/. [Accessed: ]
rf:citation
» GraphQL’s Schema Definition Language (SDL) types | Menard Maranan | Sciencx | https://www.scien.cx/2021/06/24/graphqls-schema-definition-language-sdl-types/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.