@mwarger
our job is creating value for clients and customers
our job is lists
A web api communicating via http that attempts to conform to an architecture pattern -
representational state transfer
How strictly should you adhere to the principles of REST? How do you decide which ones count?
How should you handle versioning? Should you bother?
How do you want to structure your objects? What is the shape of the data that works best for the clients of your API?
Are you sending the appropriate data to your users? Are you sending them information they don’t need?
Concerning relational or hierarchical data, are they able to efficiently query for what they need from nested structures?
Are users able to easily figure out what API endpoints are available and how they should be used?
GET: /movies
[{
id: "123",
name: "The Matrix"
},
{
id: "456",
name: "The Avengers"
}]
{
movies: [{
id: "123",
name: "The Matrix"
},
{
id: "456",
name: "The Avengers"
}]
}
POST: /graphql
{
movies {
id
name
}
}
{
id: "123",
name: "The Matrix"
}
GET: /movies/123
{
id: "123",
name: "The Matrix"
}
POST: /graphql
{
movies(id: "123") {
id
name
}
}
POST: /movies
{
name: "The Matrix"
}
{
id: "123",
name: "The Matrix"
}
POST: /graphql
mutation {
createMovie(title: "Star Wars") {
id
title
}
}
{
id: "789",
title: "Star Wars"
}
API Endpoints
GraphQL Types
Controllers
Data
Resolvers
Data
type Movie {
id: ID!
title: String!
favorite: Boolean
}
type Query {
nowPlaying: [Movie!]
movieById(id: ID!): Movie
}
type Mutation {
toggleFavoriteMovie(movieId: ID!): Movie
}
GET: /movies
[{
id: "123",
name: "The Matrix"
},
{
id: "456",
name: "The Avengers"
}]
{
movies: [
{
id: "123",
name: "The Matrix",
favorite: true,
cast: [111, 222, 333]
},
{
id: "456",
name: "The Avengers",
favorite: true,
cast: [345, 456, 567]
}
]
GET: /movies
GET: /movies/123/cast
GET: /movies/456/cast
GET: /movies?include=cast
POST: /movies/123
POST: /moviesAndCast
POST: /moviesAndCastAndStuff
[{
id: "111",
name: "Keanu Reeves",
characterName: "Neo"
}, ...]
[{
id: "345",
name: "Scarlett Johansson",
characterName: "Natasha Romanoff"
}, ...]
{
movies: [
{
id: "123",
name: "The Matrix",
favorite: true,
cast: [
{
id: 111,
name: "Keanu Reeves",
characterName: "Neo"
}
]
},
{
id: "456",
name: "The Avengers",
favorite: true,
cast: [
{
id: "1",
name: "Robert Downey Jr",
characterName: "Tony Stark"
},
{
id: "2",
name: "Scarlett Johansson",
characterName: "Natasha Romanoff"
},
]
},
{...}
]
GET: /movies
GET: /movies/123/cast
GET: /movies/456/cast
GET: /movies?include=cast
POST: /movies/123
POST: /moviesAndCast
POST: /moviesAndCastAndStuff
{
movies: [
{
id: "123",
name: "The Matrix",
favorite: true,
cast: [
{
id: 111,
name: "Keanu Reeves",
characterName: "Neo"
}
]
},
{
id: "456",
name: "The Avengers",
favorite: true,
cast: [
{
id: "1",
name: "Robert Downey Jr",
characterName: "Tony Stark"
},
{
id: "2",
name: "Scarlett Johansson",
characterName: "Natasha Romanoff"
},
]
},
{...}
]
GET: /movies
GET: /movies/123/cast
GET: /movies/456/cast
GET: /movies?include=cast
POST: /movies/123
POST: /moviesAndCast
POST: /moviesAndCastAndStuff
{
movies: [{
id: "123",
name: "The Matrix"
},
{
id: "456",
name: "The Avengers"
}]
}
POST: /graphql
{
movies {
id
name
}
}
{
movies: [
{
id: "123",
},
{
id: "456",
}
]
POST: /graphql
{
movies {
id
}
}
POST: /graphql
{
movies {
id
name
favorite
cast {
id
name
characterName
}
}
}
{
movies: [
{
id: "123",
name: "The Matrix",
favorite: true,
cast: [
{
id: 111,
name: "Keanu Reeves",
characterName: "Neo"
}
]
},
{
id: "456",
name: "The Avengers",
favorite: true,
cast: [
{
id: "1",
name: "Robert Downey Jr",
characterName: "Tony Stark"
},
{
id: "2",
name: "Scarlett Johansson",
characterName: "Natasha Romanoff"
},
]
},
{...}
]
type Movie {
id: ID!
title: String!
favorite: Boolean @deprecated(reason: "No longer needed.")
}
type Query {
nowPlaying: [Movie!]
movieById(id: ID!): Movie
}
type Mutation {
toggleFavoriteMovie(movieId: ID!): Movie
}