Skip to main content

Production App

This example includes a relatively fully featured app to demonstrate how real-world applications can be built with Grats.

https://github.com/captbaritone/grats/tree/main/examples/production-app/

Features

  • Node interface
  • dataloader
  • Connections (as used by Relay)
  • Subscriptions - See Subscription.postLikes in models/LikeConnection.ts
  • @stream - For expensive lists like Viewer.feed in models/Viewer.ts
  • Custom scalars - See Date defined in graphql/CustomScalars.ts
  • OneOf input types for modeling Markdown content in models/Post.ts
  • Look-ahead optimization for Connections to use count query for requests that only read count in graphql/gqlUtils.ts.

Implementation notes

Dataloaders are attached to the per-request viewer context. This enables per-request caching while avoiding the risk of leaking data between requests/users.

The viewer context is passed all the way through the app to the data layer. This would enable permission checking to be defined as close to the data as possible.

Libraries used

  • graphql-yoga
  • graphql-js
  • dataloader
  • @graphql-yoga/plugin-defer-stream
  • graphql-relay