0% found this document useful (0 votes)
209 views1 page

Graphql Shorthand Notation Cheat Sheet

The document provides a cheat sheet for expressing a GraphQL schema using shorthand notation, including defining object types that implement interfaces or unions, input types, scalars, enums, queries, mutations, and subscriptions. It shows examples of common schema language syntax like nullable and non-nullable fields, lists, default arguments, and custom scalar types. The cheat sheet is intended as a quick reference for concisely defining the basic structure and types in a GraphQL schema.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
209 views1 page

Graphql Shorthand Notation Cheat Sheet

The document provides a cheat sheet for expressing a GraphQL schema using shorthand notation, including defining object types that implement interfaces or unions, input types, scalars, enums, queries, mutations, and subscriptions. It shows examples of common schema language syntax like nullable and non-nullable fields, lists, default arguments, and custom scalar types. The cheat sheet is intended as a quick reference for concisely defining the basic structure and types in a GraphQL schema.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Input Arguments Interfaces

GraphQL Schema Language Cheat Sheet Basic Input Object implementing one or more Interfaces
The denitive guide to express your GraphQL schema succinctly
Last updated: 28 January 2017 type Query { interface Foo {
Prepared by: Haz Ismail / @sogko users(limit: Int): [User] is_foo: Boolean
} }
interface Goo {
What is GraphQL Schema Language? Schema Input with default value is_goo: Boolean
It is a shorthand notation to succinctly express the }
basic shape of your GraphQL schema and its type schema GraphQL schema definition
type Query { type Bar implements Foo {
system. query A read-only fetch operation users(limit: Int = 10): [User] is_foo: Boolean

mutation A write followed by fetch operation } is_bar: Boolean


What does it look like? }
subscription A subscription operation
Below is an example of a typical GraphQL schema Input with multiple arguments type Baz implements Foo, Goo {
expressed in shorthand. (experimental)
is_foo: Boolean

type Query { is_goo: Boolean


# define Entity interface users(limit: Int, sort: String): [User] is_baz: Boolean
interface Entity {
Built-in Scalar Types } }
id: ID!
name: String
} Int Int Input with multiple arguments and default values Unions
# define custom Url scalar Float Float
scalar Url type Query { Union of one or more Objects
String String users(limit: Int = 10, sort: String): [User]
# User type implements Entity interface Boolean
}
Boolean type Foo {
type User implements Entity {
id: ID! ID ID type Query { name: String
name: String users(limit: Int, sort: String = "asc"): [User] }
age: Int }
type Bar {
balance: Float
is_active: Boolean type Query { is_bar: String
friends: [User]! Type Definitions users(limit: Int = 10, sort: String = "asc"): [User] }
homepage: Url }
} union SingleUnion = Foo
scalar Scalar Type
union MultipleUnion = Foo | Bar
# root Query type type Object Type Input Types type Root {
type Query {
me: User interface Interface Type single: SingleUnion
friends(limit: Int = 10): [User]! input ListUsersInput {
multiple: MultipleUnion
union Union Type
} limit: Int
}
enum Enum Type since_id: ID
# custom complex input type
input ListUsersInput { input Input Object Type }
Unions
Enums
limit: Int type Mutation {
since_id: ID
users(params: ListUsersInput): [User]! enum USER_STATE {
}
} NOT_FOUND
# root mutation type Type Modifiers ACTIVE
type Mutation {
users(params: ListUsersInput): [User]! Custom Scalars INACTIVE
String Nullable String
} SUSPENDED
String! Non-null String scalar Url }
# GraphQL root schema type
schema { [String] List of nullable Strings type User { type Root {
query: Query name: String stateForUser(userID: ID!): USER_STATE!
[String]! Non-null list of nullable Strings
mutation: Mutation
homepage: Url users(state: USER_STATE, limit: Int = 10): [User]
subscription: ... [String!]! Non-null list of non-null Strings
} } }

You might also like