Log in to GraphQL Editor
GraphQL newbie tutorial - cheatsheet
Robert

Robert Matyszewski

11/30/2018

GraphQL newbie tutorial - cheatsheet

This article is part of newbie series. In other articles I’ve covered basics of GraphQL, introduction and Schema Definition Language. It has been written by newbie for newbies. Feel free to comment, suggest changes.

The basics

Scalar types
Int > Integer
Float > Float
String > String
Boolean > Boolean
ID > ID

Type definitions
scalar > Scalar type
type > Object type
interface > Interface type
union > Union type
enum > Enumerable type
input > Input object type

Type modifiers
String > Nullable string
String! > Required string
[String] > List of strings
[String]! > Required list of strings
[String!]! > Required list of required strings

Example of a GraphQL schema

type Author {
  id: Int!
  firstName: String
  lastName: String
  """
  the list of Books by this author
  """
  books: [Book]
}

type Book {
  id: Int!
  title: String
  author: Author
  pages: Int
}

# the schema allows the following query:
type Query {
  book: [Book]
  author(id: Int!): Author
}

Input Arguments

# Basic Input
type Root {
  users(limit: Int): [User]!
}

# Input with default value
type Root {
  users(limit: Int = 10): [User]!
}

# Input with multiple args
type Root {
  users(limit: Int, sort: String): [User]!
}
# Input with multiple args and default values
type Root {
  users(limit: Int = 10, sort: String): [User]!
}
# or
type Root {
  users(limit: Int, sort: String = "asc" ): [User]!
}
# or
type Root {
  users(limit: Int = 10, sort: String = "asc" ): [User]!
}

# Interfaces


interface Publication {
  title: String!
  releasedDate: String!
}
  
type Magazine implements Publication {
  title: String!
  releasedDate: String!
  version: Int!
}
  
type Book implements Publication {
  title: String!
  releasedDate: String!
  pages: Int!
}

# Unions

union SearchResult = Book | Author
  
type Query {
  search(text: String!): SearchResult
}

query {
  search(text: "Park") {
    ... on Book {
      title
    }
    ... on Author {
      name
    }
  }
}
    

# 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]!
}

Check out our other blogposts

Blog publish tools inside gatsby blog
Artur Czemiel
Artur Czemiel
Blog publish tools inside gatsby blog
3 min read
over 5 years ago
GraphQL Schema - The Beginner's Guide to GraphQL Editor p.1
Michał Tyszkiewicz
Michał Tyszkiewicz
GraphQL Schema - The Beginner's Guide to GraphQL Editor p.1
2 min read
almost 3 years ago
TS backend with slothking & Imp Gist implementation server
Artur Czemiel
Artur Czemiel
TS backend with slothking & Imp Gist implementation server
5 min read
over 5 years ago

Ready for take-off?

Elevate your work with our editor that combines world-class visual graph, documentation and API console

Get Started with GraphQL Editor