Skip to main content

GraphQL Reference

v1.0.0

Quick reference for GraphQL schema definitions, queries, mutations, and subscriptions

GraphQL quick-reference covering schema types, queries, mutations, subscriptions, directives, fragments, variables, error handling, and introspection. Search and filter entries by name or category.

How to use
  • Type in the search box to filter entries by name, syntax, or description.
  • Click a category chip to narrow results — click again to clear the filter.
  • Expand any entry to see the full syntax example in context.
  • Use the example picker for preset filter scenarios.

43 entries found

Object Type
Schema Types

type TypeName { field: Type }

Define a named object type with typed fields.

Scalar Type
Schema Types

scalar CustomName

Built-in scalars: Int, Float, String, Boolean, ID. Define custom scalars for special formats.

Enum Type
Schema Types

enum EnumName { VALUE_A VALUE_B }

A set of allowed string values for a field.

Input Type
Schema Types

input InputName { field: Type }

Special object type used exclusively for mutation and query arguments.

Interface
Schema Types

interface InterfaceName { field: Type }

Abstract type that concrete types must implement.

Union Type
Schema Types

union UnionName = TypeA | TypeB

A type that can be one of several object types. Resolved with inline fragments.

Non-Null (!)
Schema Types

field: Type!

The exclamation mark makes a field non-nullable — the server guarantees a value.

List Type
Schema Types

field: [Type] / [Type!]! / [Type]!

Square brackets denote a list. Combine with ! for null control on list and items.

Basic Query
Queries

query { field { subfield } }

Fetch data by selecting fields. The query keyword is optional for single operations.

Named Query
Queries

query OperationName { ... }

Name your query for debugging and logging. Required when sending multiple operations.

Query Arguments
Queries

field(arg: value)

Pass arguments to fields to filter or parameterise results.

Aliases
Queries

alias: field(arg: value)

Rename a field in the response to avoid conflicts when querying the same field twice.

Nested Fields
Queries

field { nested { deep } }

Traverse object relationships by nesting field selections.

Connection / Pagination
Queries

field(first: N, after: cursor) { edges { node } pageInfo }

Relay-style cursor-based pagination for large datasets.

Basic Mutation
Mutations

mutation { action(input: {}) { result } }

Write operations that create, update, or delete data.

Named Mutation
Mutations

mutation OperationName($var: Type!) { ... }

Named mutation with variables for reusable, parameterised writes.

Update Mutation
Mutations

mutation { updateEntity(id: ID!, input: {}) { ... } }

Modify an existing record by ID with partial input.

Delete Mutation
Mutations

mutation { deleteEntity(id: ID!) { success } }

Remove a record and return confirmation.

Batch Mutation
Mutations

mutation { a: action(...) { } b: action(...) { } }

Execute multiple mutations in a single request using aliases. They run sequentially.

Optimistic Response
Mutations

optimisticResponse: { ... }

Client-side pattern: predict the mutation result to update the UI immediately before the server responds.

Basic Subscription
Subscriptions

subscription { event { field } }

Real-time data pushed from the server over WebSocket.

Named Subscription
Subscriptions

subscription OpName($var: Type!) { ... }

Named subscription with variables for parameterised real-time streams.

Subscription Filter
Subscriptions

subscription { event(filter: value) { ... } }

Server-side filtering so the client only receives relevant events.

Schema Subscription Type
Subscriptions

type Subscription { event: Type }

Define subscription fields in the schema root.

@skip
Directives

field @skip(if: $condition)

Conditionally exclude a field when the Boolean variable is true.

@include
Directives

field @include(if: $condition)

Conditionally include a field when the Boolean variable is true.

@deprecated
Directives

field: Type @deprecated(reason: "...")

Mark a field or enum value as deprecated in the schema.

Custom Directive
Directives

directive @name(arg: Type) on FIELD_DEFINITION

Define custom schema directives for cross-cutting concerns like auth or caching.

@specifiedBy
Directives

scalar Name @specifiedBy(url: "...")

Link a custom scalar to its specification URL.

Fragment
Fragments & Variables

fragment Name on Type { fields }

Reusable field selection set — avoids repeating the same fields across queries.

Inline Fragment
Fragments & Variables

... on Type { fields }

Select fields conditionally based on the concrete type (for unions and interfaces).

Variables
Fragments & Variables

query($var: Type!) { field(arg: $var) }

Parameterise operations with typed variables — passed as a separate JSON object.

Default Variable Value
Fragments & Variables

query($var: Type = defaultValue) { ... }

Provide a fallback value when the variable is not supplied.

Variable in Fragment
Fragments & Variables

fragment Name on Type { field(arg: $var) }

Fragments can reference variables defined in the operation that spreads them.

errors Array
Error Handling

{ "errors": [{ "message": "..." }] }

GraphQL responses include an errors array alongside data — partial success is possible.

Error Extensions
Error Handling

extensions: { code: "...", ... }

Custom error metadata — use the extensions field to add error codes and details.

Union Error Pattern
Error Handling

union Result = Success | Error

Model errors as part of the schema using union return types instead of relying on the errors array.

__schema
Tooling & Introspection

{ __schema { types { name } } }

Introspect the entire schema — list all types, directives, and the query/mutation/subscription roots.

__type
Tooling & Introspection

{ __type(name: "TypeName") { fields { name } } }

Introspect a single type — list its fields, arguments, and descriptions.

__typename
Tooling & Introspection

{ field { __typename } }

Meta-field available on every type — returns the concrete type name at runtime.

Schema Description
Tooling & Introspection

"""Description""" type Name { ... }

Add documentation strings to types, fields, and arguments — visible in GraphiQL/Playground.

Schema Stitching / Federation
Tooling & Introspection

@key(fields: "id") / extend type

Compose multiple GraphQL services into a single unified graph (Apollo Federation pattern).

Persisted Queries
Tooling & Introspection

extensions: { persistedQuery: { sha256Hash } }

Send a query hash instead of the full query string — reduces bandwidth and prevents arbitrary queries.