engine • GraphQL Exec Engine – Calls resolvers in right order & builds response • Schema & Resolvers – Defined and implemented by user to fetch data How GraphQL servers work RECAP
GraphQL API (Ask: What can I query for?) • Foundation for resolver functions • Intuitive representation as GraphQL SDL • Defined programmatically or declaratively type Query { posts: [Post!]! } type Post { id: ID! title: String! content: String! }
The query type, represents all of the entry points into our object graph type Query { hero(episode: Episode): Character reviews(episode: Episode!): [Review] search(text: String): [SearchResult] character(id: ID!): Character droid(id: ID!): Droid human(id: ID!): Human starship(id: ID!): Starship } # The mutation type, represents all updates we can make to our data type Mutation { createReview(episode: Episode, review: ReviewInput!): Review } # The subscription type, represents all subscriptions we can make to our data type Subscription { reviewAdded(episode: Episode): Review How to deal with large schemas?
SOURCE OF TRUTH EXAMPLES Nexus (JS/TS), Sangira (Scala), Graphene (Python) const Post = objectType('Post', t => { t.id('id') t.string(‘title') t.string(‘content') }) type Post { id: ID! slug: String! content: String! } SDL is auto-generated
system • Speeds up development (even in prototyping stage) • Based on built-in, self-updating type generation (disabled in prod) • Type-safe “areas” • Resolvers: Parent values, arguments, context, return values • Type <> Model mapping • Nexus API: Configuration & schema building