Unlike REST APIs, GraphQL exposes a single endpoint.
Consumers read data from the graph with Queries, and change data on the graph with Mutations
By analogy to REST:
POST, PUT, DELETE
Even if the database schema doesn't match your query...
...you can still respond sensibly.
The GraphQL Schema tells your server the type of each object.
The resolvers define the contents of each field.
An opinionated framework for implementing GraphQL Apps
Front-end data store
"Redux", but GraphQL
Network & Client State
Quickly Bootstrap your Server
Deploy to Cloud Providers
Stores its data in a normalized cache
Manage local state with GraphQL queries and mutations
Base-classes and Mixins for many Web Component Libraries
👩🚀 Apollo for Data Layer
🚒 LitElement for View Layer & Reactivity
✅ TypeScript typings
🤝 Pairs well with...
ApolloQuery base class
Write UI components that update your graph
Say we had a list component that should toggle an `isBestFriend` flag on any member of the list.
Let's define <toggle-friend> as a mutation component!
Mutations - DOM
Mutations - Optimistic UI
Mutations - Updating the Cache
Only load resolvers when components are needed.
Leverage the PRPL-pattern to keep the UX snappy.
GraphQL Error Handling
Handle GraphQL Errors
The Limitations of GraphQL
GraphQL type properties are optional by default. Non-nullability is opt-in.
This general programming gripe takes on acute significance when your app deals in deeply nested optionals.
Different languages have different constructs to help with this, e.g Maybe.
GraphQL objects must come with a __typename property.
Omitting it when writing data to the Apollo cache throws an error.
It may not be obvious from the stack trace where the error originates, so make sure to always include the __typename.
Forgetting to query for ID
The Apollo cache is normalized by object ID and__typename.
So if you already have an object in your cache, apollo won't fetch it twice unless you tell it to.This means that if you query for an object and its ID once, you have to always query for it by ID.