Drop Image

Avatar

what is GraphQL SDL?

GraphQL SDL (Schema Definition Language) is a language used to define the schema for a GraphQL API. It allows you to specify the types, queries, mutations, subscriptions, and directives that make up the GraphQL schema.

Some key things about GraphQL SDL:

  • It is used to define the structure and capabilities of a GraphQL API. The schema serves as a contract between the client and the server.

  • SDL is human readable and declarative. It describes the API in an easy to understand way.

  • The schema is typically defined in a .graphql schema file. This file contains type definitions, query/mutation fields, resolvers, etc.

  • Types can represent objects, interfaces, unions, enums, inputs, scalars etc. Fields, arguments and directives can be added to the types.

  • The schema stiches together individual types into a unified graph. This allows clients to query exactly what they need in a single request.

Avatar

show small example

Here is a simple example of a GraphQL schema defined with SDL:

Graphql
Graphql

This defines:

  • A Query type with a "books" field that returns a list of Book objects

  • A Book type with "title" and "author" fields

  • An Author type with "name" and "books" fields

  • The types reference each other to model their relationships

This simple schema allows clients to query books and their related authors. The GraphQL server would provide the corresponding resolvers to return actual data for the schema.

So in summary, this SDL defines the structure of the API that clients can query. The resolvers and data sources are implemented separately.

Shared byo-az