What the hell is GraphQL?
It's an alternative way to design APIs... that's all

It all starts with the Schema

Instead of loads of endpoints like this

GET http://api.com/users/1
POST http://api.com/users

We have one endpoint

http://api.com/graphql

Where we send queries and mutations

{
  "name": "Dara",
  "address": "waterford"
}

Quick Recap

  • Schema - Definition of Data + queries & mutations
  • Resolver - A function that implements a query or mutation
  • Nested Resolvers - very powerful way to resolve (mostly relational) data
  • Subscription - subscribe to events over websockets
    • Fire events (e.g. 'messageAdded') on a pubsub instance
    • Subscription resolver listens for those events and sends them back down to clients
    • Can add filtering on subscriptions

Aerogear Data Sync Server

  • Schema is defined in UI by end user. Saved in the metadata db (postgres)
  • DataSources allow users to specify where data comes from. (Postgres, InMemory, Mongo, etc)
  • Resolver Mappings tell the server how to perform the particular query/mutation (e.g. run an SQL statement)
  • As part of resolver definition, end user can define a 'publish' field for subscriptions

Aerogear Data Sync Server (continued)

  • We are using Apollo Server V1. Be very aware that most docs on Apollo's website are for V2.
  • Pubsub - using Notify/Listen mechanism in Postgres
  • Schema Changes are Hot Reloaded - when a change is made via UI, a message is published on the pubsub. Server picks this up and reloads schema without restarting
  • Subscriptions use the Postgres Pubsub mechanism. This allows subscriptions to work across several server instances

GraphQL knowledge sharing session

By Dara Hayes

GraphQL knowledge sharing session

  • 427

More from Dara Hayes