GraphQL (Graph Query Language) is an open-source data query and manipulation language for APIs and a runtime for fulfilling queries with existing data.
A GraphQL schema represents your application’s data graph and the operations on it. It also defines the queries and mutation functions to read and write data from the GraphQL server.
Think graph, not endpoints.
A GraphQL schema is written in SDL ( schema definition language), which supports the following basic type categories:
Int
, Float
, String
, Boolean
, and ID
.type Book {id: ID!title: Stringauthor: Author}type Author {id: ID!name: Stringbooks: [Book]}
Arguments: Every field on a GraphQL object type can have zero or more named arguments.
The Query type: Query types define all of the top-level entry points for queries that the client executes against your data graph. Queries match the shape of the object types you define in your schema.
type Query {books: [Book]authors: [Author]}
query GetBooks {books {titleauthor {name}}}
type Mutation {addBook(title: String, author: String): Book}
More advanced type categories:
Input type: Input types are special object types that allow you to pass objects as arguments to queries and mutations.
The Enum type: An enum is similar to a scalar type, but its legal values are defined in the schema.
Interfaces: An Interface is an abstract type that includes a certain set of fields that a type must include to implement the interface.
Union type: Union types define the object types included in the union.
GraphQL schema defines the signature of your GraphQL API, but it’s not yet functional. Make it functional by building a server in the language of your choice, as mentioned in the official documentation.