Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// GraphQL Shorthand Notation Cheatsheet
// - Read the full article at: https://wehavefaces.net/graphql-shorthand-notation-cheatsheet-17cd715861b6
Schema
=======
GraphQL Schema => schema
Built-in scalar types
=====================
GraphQL Int => Int
GraphQL Float => Float
GraphQL String => String
GraphQL Boolean => Boolean
GraphQL ID => ID
Type Definitions
================
Scalar Type => scalar
Object Type => type ... (implements ...)
Interface Type => interface
Union Type => union
Enum Type => enum
Input Object Type => input
Type Markers
============
Non-null Type => <type>! e.g String!
List Type => [<type>] e.g [String]
List of Non-null Types => [<type>!] e.g [String!]
Non-null List Type => [<type>]! e.g [String]!
Non-null List of Non-null Types => [<type>!]! e.g [String!]!
Input Arguments
============
Basic input
e.g: users(limit: Int): [User]
Input with default value
e.g: users(limit: Int = 10): [User]
Input with multiple args
e.g: users(limit: Int, since_id: ID): [User]
Input with multiple args & default value
e.g: users(limit: Int = 10, since_id: ID): [User]
e.g: users(limit: Int, since_id: ID = 0): [User]
e.g: users(limit: Int = 10, since_id: ID = 0): [User]
Interfaces
===========
Object implementing an Interface, e.g:
interface Foo {
name: String
}
type Bar implements Foo {
name: String
is_bar: Boolean
}
Object implementing multiple Interfaces, e.g:
interface Foo {
name: String
}
interface Doo {
is_doo: Boolean
}
type Bar implements Foo, Doo {
name: String
is_doo: Boolean
is_bar: Boolean
}
Unions
======
Union of a single Object e.g:
type Foo {
name: String
}
union SingleUnion = Foo
Union of multiple Objects e.g:
type Foo {
name: String
}
type Bar {
is_bar: Boolean
}
union MultipleUnion = Foo | Bar
Enums
=====
enum RGB {
RED
GREEN
BLUE
}
type Root {
color: RGB
}
Input Object Types
===================
input ListUsersInput {
limit: Int
since_id: ID
}
type Root {
users(params: ListUsersInput): [Users]!
}
Custom Scalar
==============
scalar Url
type User {
name: String
homepage: Url
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.