GraphQL

In Construction Module (Backend)

by Leszek Zalewski

Integration

Setup with `graphql-ruby` which is used by Shopify

Easy introduction into existing legacy application

Integration with GraphiQL for easier local evaluation

Authentication done with OAuth2 tokens

"Lazy" by default

Removes the burden of query language definition for selecting and retrieving fields

Queries are always explicit, so by fetching data that's needed we reduce used bandwidth between server and client as well as optimize database queries

Schema

Helps to document and establish API contract between Server and Clients.

Live Testing

Using Postman we specify different arguments combination which we can run against automated tests.

Construction SPA

Using apollo client.

Some quirks

  • Lookout for N+1 and too greedy queries (various ways to optimize, based on context)
  • Not so easy to lookup the selected fields by query (need to dig through internal structure of graphql-ruby to see which ones will get fetched)
  • Response supports only JSON format (would be good to have something like Protocol Buffers, etc)
  • Apollo caching - after "mutation" query, next query doesn't  always go to server (need to be explicit)

Questions?

Made with Slides.com