Skip to content

GraphQL

James Gibson edited this page Jan 13, 2022 · 6 revisions

GraphQL

Things to learn

Things to prototype

  • Finish federation prototype
  • Schematics

Relevant Libraries

Apollo

Nexus

Declarative, Code-First GraphQL Schemas for JavaScript/TypeScript https://nexusjs.org/

Prisma

Node.js and TypeScript ORM https://www.prisma.io/docs/concepts/overview/prisma-in-your-stack/graphql https://www.prisma.io/docs/concepts/overview/should-you-use-prisma https://marketplace.visualstudio.com/items?itemname=prisma.prisma

Supports Postgresql, MySql, SqlLite, Sql Server. Similar to knex

Prisma Studio

https://www.prisma.io/docs/concepts/components/prisma-studio

Schema first vs Code first

Schema First

GraphQL initially only supported code first, so schema first was created to fill in some gaps Based around the SDL (get link). Simple graphs benefit, works best if there are a limited number of types to manage.

https://blog.logrocket.com/code-first-vs-schema-first-development-graphql/ https://medium.com/novvum/graphql-code-first-and-sdl-first-the-current-landscape-in-mid-2019-699f68b31a65

Code First

Multiple ways to implement. Most libraries do not yet support directives which causes issues with federation.

Scaling

Schema Stitching

Difficult to manage, resolution logic becomes detached from implementation

Federation

Officially only supported by Apollo (currently). To use with other libraries currently you need to use https://github.com/0xR/graphql-transform-federation

It allows subgraphs to be domain specific. Given subgraphs [ users, books, reviews ] users and books are not related, while reviews relates to users by id (key fields, important) and books by id/isbn. The federated gateway uses the full graph to plan (query planner, gateway only) and execute each subquery against the relevant subgraphs. Once resolved the gateway assembles all the responses into the proper format.

Subgraphs extend types. Apollo magic keeps it aligned.

Each subgraph should be validated in context of the whole graph prior to releasing

Links

https://blog.logrocket.com/the-what-when-why-and-how-of-federated-graphql/ https://github.com/apollographql/federation-demo#apollo-federation-demo https://principledgraphql.com/ https://medium.com/pipedrive-engineering/journey-to-federated-graphql-2a6f2eecc6a4 https://www.apollographql.com/docs/federation/managed-federation/deployment/ https://www.fastly.com/blog/exploring-the-security-implications-of-graphql