Eve Porcello
@eveporcello
eve@moonhighway.com
- Unions / Interfaces
- Fragments
- Understanding Schemas
- Caching / Performance
- Errors
- Q+A
- 11:00 - Start
- 12:00 - 12:05 - Break
- 1:00 - End
enum PetCategory
DOG
CAT
STINGRAY
RABBIT
type Pet
id: ID!
name: String!
category: PetCategory!
...
HORSE
sleepAmount: Int
curious: Boolean
favoriteFood: String
floppy: Int
good: Boolean
chill: Boolean
fast: Boolean
streetsmart: Boolean
majestic: Boolean
interface Pet
type Cat implements Pet
id: ID!
name: String
...
sleepAmount: Int
curious: Boolean
id: ID!
name: String!
weight: Float
status: PetStatus
photo: Photo
dueDate: Date
inCareOf: Customer
type Dog implements Pet
id: ID!
name: String
...
good: Boolean
type Rabbit implements Pet
id: ID!
name: String
...
favoriteFood: String
floppy: Int
type Stingray
implements Pet
id: ID!
name: String
...
chill: Boolean
fast: Boolean
type Horse
implements Pet
id: ID!
name: String
...
streetsmart: Boolean
majestic: Boolean
type *TBDFuturePet
implements Pet
id: ID!
name: String
...
newField: _____
newField: _____
type Query {
familyPets: [FamilyPets!]!
}
union FamilyPet = Cat | Dog
Query
query {
familyPets {
__typename
...on Cat {
name
weight
}
...on Dog {
name
status
}
}
}
id: ID!
name: String!
type Photo {
id: ID!
name: String!
url: String!
description: String
rating: Float
private: Boolean!
}
name: String!
description: String
type Query {
totalUsers: Int!
}
type User {
postedPhotos: [Photo!]!
}
photos: [Photo]
photos: [Photo]!
photos: [Photo!]!
Nullable list of nullable values
Non-nullable list of nullable values
Non-nullable list of non-nullable values
photos: [Photo!]
Nullable list of non-nullable values
enum PhotoCategory {
PORTRAIT
ACTION
LANDSCAPE
}
type Photo {
postedBy: User!
}
type User {
postedPhotos: [Photo!]!
}
type Student {
schedule: [Course!]!
}
type Course {
students: [Student!]!
}
type City {
name: String!
connections: [City!]!
}
BOISE
SUN VALLEY
BEND
155 MILES
318 MILES
type City {
name: String!
connections: [Connection!]!
}
type Connection {
distance: Int!
to: City!
}
BOISE
SUN VALLEY
155 MILES
BEND
318 MILES
type Mutation {
postPhoto: Boolean!
}
type Mutation {
postPhoto (name: String!): Photo!
}
input PostPhotoInput {
name: String!
category: PhotoCategory=PORTRAIT
description: String
}
mutation addPhoto ($input: PostPhotoInput!) {
postPhoto(input: $input) {
id
name
url
}
}
{
"input": {
"name": "Desert Sunset",
"description": "Sunset over Sedona",
"category": "LANDSCAPE"
}
}
Query Variables
type Subscription {
newPhoto: Photo!
}
scalar DateTime
type Photo {
created: DateTime!
updated: DateTime!
}
type Schedule {
agenda: [AgendaItem!]!
}
union AgendaItem = StudyGroup | Workout
query {
agenda {
...on Workout {
name
reps
}
...on StudyGroup {
name
subject
students
}
}
}
Query
interface ScheduleItem {
name: String!
start: Int
end: Int
}
type StudyGroup implements ScheduleItem {
name: String!
start: Int
end: Int
students: Int!
}
type Workout implements ScheduleItem {
name: Location!
start: Int
end: Int
reps: Int!
}
type Query {
agenda: [ScheduleItem!]!
}
enum PetCategory
DOG
CAT
STINGRAY
RABBIT
type Pet
id: ID!
name: String!
category: PetCategory!
...
HORSE
sleepAmount: Int
curious: Boolean
favoriteFood: String
floppy: Int
good: Boolean
chill: Boolean
fast: Boolean
streetsmart: Boolean
majestic: Boolean
interface Pet
type Cat implements Pet
id: ID!
name: String
...
sleepAmount: Int
curious: Boolean
id: ID!
name: String!
weight: Float
status: PetStatus
photo: Photo
dueDate: Date
inCareOf: Customer
type Dog implements Pet
id: ID!
name: String
...
good: Boolean
type Rabbit implements Pet
id: ID!
name: String
...
favoriteFood: String
floppy: Int
type Stingray
implements Pet
id: ID!
name: String
...
chill: Boolean
fast: Boolean
type Horse
implements Pet
id: ID!
name: String
...
streetsmart: Boolean
majestic: Boolean
type *TBDFuturePet
implements Pet
id: ID!
name: String
...
newField: _____
newField: _____
type Query {
familyPets: [FamilyPets!]!
}
union FamilyPet = Cat | Dog
Query
query {
familyPets {
__typename
...on Cat {
name
weight
}
...on Dog {
name
status
}
}
}
Query
Response
Query
Response
Gateway
Query
Response
Gateway
Reviews
Colors
Accounts
query {
cat(name:"Biscuit") {
name
location
mood
}
}
{
"data": {
"cat": {
"name":"Biscuit",
"location": "Tahoe City",
"mood": "pensive"
}
}
}
POST /graphql
Query
mutation {
setLiftStatus(
name:"Panorama",
newStatus: "hold"
) {
name
newStatus
oldStatus
}
}
{
"data": {
"setLiftStatus": {
"name": "Panorama",
"newStatus": "hold",
"oldStatus": "open"
}
}
}
POST /graphql
Mutation
subscription {
liftStatusChange {
name
newStatus
oldStatus
}
}
{
"data": {
"setLiftStatus": {
"name": "Panorama",
"newStatus": "hold",
"oldStatus": "open"
}
}
}
WebSockets
Subscription
{
"data": {
"setLiftStatus": {
"name": "Astra Express",
"newStatus": "closed",
"oldStatus": "open"
}
}
}
{
"data": {
"setLiftStatus": {
"name": "Panorama",
"newStatus": "closed",
"oldStatus": "open"
}
}
}
query {
cat(name: "Biscuit") {
name
location
birthLocation
weight
gpa
astrologicalSign
hangingInThere
bicyclePreference
isADentist
knowsADentist
siblings {
name
location
}
}
}
query {
cat(name: "Biscuit") {
name
location
birthLocation
weight
gpa
astrologicalSign
hangingInThere
bicyclePreference
isADentist
knowsADentist
siblings {
name
location
}
}
}
query {
cat(name: "Biscuit") {
name
location
birthLocation
}
}
query {
cat(name: "Biscuit") {
name
location
birthLocation
weight
...ExtraneousCatDetails @defer
}
}
fragment ExtraneousCatDetails on Cat {
gpa
astrologicalSign
hangingInThere
bicyclePreference
isADentist
knowsADentist
}
query {
cat(name: "Biscuit") {
name
friends {
name
}
}
}
query {
cat(name: "Biscuit") {
name
friends @stream(initialCount: 3) {
name
}
}
}
query {
cat(name: "Biscuit") {
name
friends @stream(initialCount: 3) {
name
...ExtraneousCatFields @defer
}
}
}