By: Ryan Kanner @CodeProKid
©2020 Copyright - Confidential and Proprietary
Live in Denver, CO
Engineer on the Content Platform / WordPress team @ NerdWallet
Co-organizer of GraphQL & WordPress meetups in Denver
Help maintain WPGraphQL, an open source project bringing GraphQL to WordPress
Crazy dog, Blake
Baseball Fan
©2020 Copyright - Confidential and Proprietary
©2020 Copyright - Confidential and Proprietary
©2020 Copyright - Confidential and Proprietary
©2020 Copyright - Confidential and Proprietary
©2020 Copyright - Confidential and Proprietary
query {
specials: [Pizza]
}
type Pizza {
id: ID!
image: String
name: String!
sauce: String
cheese: String
toppings: [String]
price: Float!
}
©2020 Copyright - Confidential and Proprietary
type Pizza {
id: ID!
image: String
name: String!
sauce: String
cheese: String
toppings: [String]
price: Float!
}
type Side {
id: ID!
image: String
name: String!
sauce: String
cheese: String
quantity: Int
price: Float!
}
interface FoodItem {
id: ID!
image: String
name: String!
sauce: String
cheese: String
price: Float!
}
query {
specials: [FoodItem!]
}
©2020 Copyright - Confidential and Proprietary
interface FoodItem {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
}
©2020 Copyright - Confidential and Proprietary
type Pizza implements FoodItem {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
toppings: [String!]
}
type Side implements FoodItem {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
quantity: Int
}
©2020 Copyright - Confidential and Proprietary
query FEATURED_ITEMS {
specials {
__typename
id
name
image
price
sauce
cheese
... on Pizza {
toppings
}
... on Side {
quantity
}
}
}
type Query {
specials: [FoodItem!]
}
interface FoodItem {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
}
type Pizza implements FoodItem {
...
toppings: [String]
}
type Side implements FoodItem {
...
quantity: Int
}
©2020 Copyright - Confidential and Proprietary
type Query {
specials: [FoodItem!]
}
union FoodItem = Pizza | Side
type Pizza {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
crust: String
}
type Side {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
quantity: Int
}
query FOOD_ITEM_UNION {
specials {
__typename
... on Pizza {
id
name
price
image
sauce
cheese
crust
}
... on Side {
id
name
price
image
sauce
cheese
quantity
}
}
}
©2020 Copyright - Confidential and Proprietary
FoodItem
Pizza
- toppings
Side
- quantity
FoodItem
Pizza
Side
Interfaces
Unions
©2020 Copyright - Confidential and Proprietary
©2020 Copyright - Confidential and Proprietary
type Pizza {
id: ID!
image: String
name: String!
price: Float!
sauce: String
cheese: String
toppings: [String]
}
type Side {
id: ID!
image: String
name: String!
price: Float!
sauce: String
cheese: String
quantity: Int
}
type Apparel {
id: ID!
image: String
name: String!
price: Float!
inStock: Boolean!
description: String
}
©2020 Copyright - Confidential and Proprietary
interface FoodItem {
sauce: String
cheese: String
}
type Apparel implements
Product {
id: ID!
name: String!
price: Float!
image: String
inStock: Boolean!
description: String
}
interface Product {
id: ID!
name: String!
price: Float!
image: String
}
type Pizza implements
FoodItem & Product {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
toppings: [String]
}
type Side implements
FoodItem & Product {
id: ID!
name: String!
price: Float!
image: String
sauce: String
cheese: String
quantity: Int
}
©2020 Copyright - Confidential and Proprietary
type Query {
specials: [Product!]
}
query FEATURED_ITEMS {
specials {
__typename
id
name
image
price
... on FoodItem {
sauce
cheese
}
... on Pizza {
toppings
}
... on Side {
quantity
}
... on Apparel {
inStock
description
}
}
}
Pizza
Apparel
Side
©2020 Copyright - Confidential and Proprietary
<ProductCard>
fragment pf on Product {
__typename
id
name
price
image
... foodFields
... apparelFields
}
<FoodItemDetails>
fragment foodFields
on FoodItem {
__typename
sauce
cheese
... on Pizza {
toppings
}
... on Side {
quantity
dippingSauce: sauce
}
}
<ApparelDetails>
fragment apparelFields
on Apparel {
inStock
description
}
©2020 Copyright - Confidential and Proprietary
Pizza
GET /api/v99/pizza/1
Apparel
GET /api/v99/apparel/2
Side
GET /api/v99/side/3
©2020 Copyright - Confidential and Proprietary
©2020 Copyright - Confidential and Proprietary