Catalog / GraphQL Cheatsheet
GraphQL Cheatsheet
A concise reference for GraphQL syntax, schema definition, queries, mutations, and common directives, designed for quick lookup and efficient development.
GraphQL Basics
Core Concepts
GraphQL: A query language for your API and a server-side runtime for executing those queries. It provides a complete and understandable description of the data in your API, giving clients the power to ask for exactly what they need and nothing more. |
Schema: The foundation of a GraphQL API. It defines the data types (objects) available and the operations (queries and mutations) that can be performed. |
Queries: Used to fetch data. Clients specify the data they need in a structured format. |
Mutations: Used to modify data (create, update, delete). Similar in structure to queries but indicate an intent to change data. |
Resolvers: Functions that fetch the data for a particular field in the schema. |
Basic Syntax
Query: |
|
Mutation: |
|
Fragment: |
|
Schema Definition Language (SDL)
Object Types
Defines the structure of data objects.
|
Queries and Mutations
Query Example: |
|
Mutation Example: |
|
Input Types
Used to define the structure of input arguments for mutations.
|
Queries in Detail
Basic Queries
A simple query to fetch a user’s name and email.
|
Arguments
Passing arguments to filter or specify the data being fetched.
|
Aliases
Rename the fields in the response.
|
Fragments
Reusable units of query logic.
|
Inline Fragments
Used when dealing with interfaces or unions.
|
Mutations in Detail
Basic Mutations
A simple mutation to create a user.
|
Arguments and Input Types
Using input types for complex arguments.
|
Returning Updated Data
Mutations typically return the updated data.
|