&
graphql-ruby
Two weeks ago
This week
{
id: 1,
name: "Chan's Great Adventure",
genres: [
"Adventure",
"Comedy",
"Romance"
],
sequels: [
{ /* ... */ },
{ /* ... */ },
{ /* ... */ },
{ /* ... */ }
]
}
{
id: 1,
name: "Chan's Great Adventure",
genres: [
"Adventure",
"Comedy",
"Romance"
]
}
What I get
What I care about
{
id: 1,
name: "Chan's Great Adventure",
genres: [
"Adventure",
"Comedy",
"Romance"
],
sequels: [
{ /* ... */ },
{ /* ... */ },
{ /* ... */ },
{ /* ... */ }
],
pi: 3.1415926535897932384626433832795028841971693993751
}
{
name: "Chan's Great Adventure",
}
Request
Response
query getChansAdventure {
movie(id: 1) {
name,
sequels {
name
}
}
}
{
data: {
movie: {
name: "Chan's Great Adventure",
sequels: [
"Chan in Trouble",
"Chan Goes for the Gold",
"Chan Maxes Out",
"SpyKids 5: Origins of Chan"
]
}
}
}
Explicit, Nested
Build a Schema
Make a Request
MovieType = GraphQL::Type.new do
name "Movie"
description "Full-length feature film"
fields({
name: field(type: !type.String),
staring: field(type: type[ActorType]),
sequels: field(type: type[MovieType]),
})
end
# ...
Schema = GraphQL::Schema.new(
query: QueryType,
mutation: MutationType,
)
query_string = "
query getChan {
movie(id: 1) { name }
}"
query = GraphQL::Query.new(
Schema,
query_string
)
puts query.execute