转自: https://tomasalabes.me/blog/graphql/node/microservices/2018/08/11/graphql-architectures.html

GraphQL Gateway Architectures

These are the approaches we will see:

  • Remote Schema Stitching
  • Schema Stitching through Shared Interfaces
  • Hybrid Remote Schema Stitching
  • Using Prisma’s graphQL Bindings

Let’s start.

Remote schema stitching

Stitching strategy

  • The gql gateway builds the schema exposed to the client as a mashup of many remote graphql schemas (link)

    • This lets the graphql servers evolve independently from the gateway but
  • The dynamic nature of this can be tricky, as the final API is “dispersed”, interaction between schemas can become complicated, maybe needing the following:
    • You might have merge conflicts (more) or transformations (more)
    • Without proper testing, remote schemas might change and the gateway becomes out of date / broken
  • All services that expose some graphQL schema will be a graphQL server, exposing the usual /graphql endpoint.
  • Each service can choose in what language implement the graphQL server

Schema stitching through shared interfaces

NPM interfaces strategy

  • The gql gateway builds the schema exposed to the client as a mashup of many local graphql schemas (more)
  • These schemas are installed as npm packages
  • Development is easier as you have the schemas installed locally and you have the “source of truth” for the final API
  • The gateway will became a bottleneck, being modified by many teams as it has all resolvers and types
  • A change in any resolver or schema means redeploying the gql gateway and the service (high cohesion)

Hybrid Remote Schema Stitching

Hybrid resolvers strategy

This is a very simple variation from the previous 2 architectures. It’s just being able to not only delegate requests to other graphQL servers through schema stitching but also contain resolvers for other services.

  • The graphQL gateway communicates with Service A through a resolver implementation in the gateway itself (approach #2)
  • The graphQL gateway communicates with Service B through schema stitching (approach #1)

Using Prisma’s graphQL Bindings

This approach uses prima’s graphQL bindings. Think of it as a client built from a graphQL schema and its resolvers.

Prisma Bindings

So the collaboration diagram would be something like

Bindings strategy

Where

  • Service A and B publish a binding with all the resolvers for their types, queries and mutations
  • These bindings are consumed by the gateway and used to communicate with these services
  • This avoids the actual resolvers implementation in the gateway, and even in the services themselves
  • The development of the resolvers is done by the team developing the service in question

Conclusion

As always, your choice depends on many factors. Team, knowledge, time, etc. Some are simpler, some are more decoupled, some require more work.

Pick yours and give me your opinion! Or propose more!

Cheers

GraphQL Gateway Architectures的更多相关文章

  1. 使用merge-graphql-schemas 进行graphql schema 以及resovler 合并

    merge-graphql-schemas 是一个方便的工具,可以进行schema 以及resovler 的合并处理 一个schema 合并参考demo schema 定义 // ./graphql/ ...

  2. 基于 GraphQL 的 BFF 实践

    随着软件工程的发展,系统架构越来越复杂,分层越来越多,分工也越来越细化.我们知道,互联网是离用户最近的行业,前端页面可以说无时无刻不在变化.前端本质上还是用户交互和数据展示,页面的高频变化意味着对数据 ...

  3. QLoo graphql engine 学习一 基本试用(docker&&docker-compose)

      说明:使用docker-compose 进行安装 代码框架 使用命令行工具创建 qlooctl install docker qloo-docker 运行qloo&&gloo 启动 ...

  4. hasura graphql 模式拼接概念

    具体的使用可以参考下面一张图 有一个术语 graphql-bindings 参考项目: https://github.com/hasura/generate-graphql-bindings http ...

  5. Why GraphQL is Taking Over APIs

    A few years ago, I managed a team at DocuSign that was tasked with re-writing the main DocuSign web ...

  6. Uber的API生命周期管理平台边缘网关(Edge Gateway)的设计实践

    设计边缘网关(Edge Gateway),一个高可用和高可扩展的自助服务网关,用于配置.管理和监控 Uber 每个业务领域的 API. Uber 的 API 网关的演进 2014 年 10 月,优步开 ...

  7. 记一次nginx部署yii2项目时502 bad gateway错误的排查

    周六闲来无事,就试着安装和部署下yii2,安装过程没什么问题,但部署到nginx上时遇到了502 bad gatewary问题,折腾了半天才搞定.这个问题是我以前在部署yii2时没有遇到过的,因此记在 ...

  8. tomcat 504 gateway time-out

    今天有个环境ajax调用一个请求的时候,出现一个504 gateway time-out响应,原以为是nginx找不到资源的问题,恰当我们的服务器上又配置了nginx,看了配置文件,没有指向tomca ...

  9. linux查看本机IP、gateway、DNS

    IP:     ifconfig gateway:[root@localhost ~]# netstat -rnKernel IP routing tableDestination     Gatew ...

随机推荐

  1. error MSB8008: 指定的平台工具集(V120)未安装或无效。

    打开项目属性->配置属性->右面,平台工作集,选为v10 如下图

  2. SecureCRT使用(转)

      功能介绍 连接概述    1.当您启动SecureCRT时,您将看到“快速连接”对话框与主SecureCRT窗口一起出现.  2.有几种接口可用于连接远程机器:快速连接对话框,工具栏上的连接栏,会 ...

  3. FutureTask

    因为实现了runnable接口,所以重写了run方法 Future接口如果用在多线程中,实现类一般是有一个volatile的属性,用来标志状态,比如state,如果事情做完了,那么会设置state为成 ...

  4. css3渐变 两边透明中间高亮

    颜色自己可以调节 如图: 采集器管理下面的那条线就是 css代码: .linear{            width:100%;            height:2px;            ...

  5. HDU 6092 17多校5 Rikka with Subset(dp+思维)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  6. PAT 乙级 1061. 判断题(15)

    判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分. 输入格式: 输入在第一行给出两个不超过100的正整数N和M,分别是学生人数和判断题数量.第二行给出M个不超过5的正 ...

  7. 批注@SuppressWarnings 的作用

    J2SE 提供的最后一个批注是 @SuppressWarnings.该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默. 一点背景:J2SE 5.0 为 Java 语言增加 ...

  8. Go unitest

    待测试: // add.go package util func Add(a int, b int) int { return a + b} 使用gotests工具,自动生成测试用例框架: https ...

  9. MongDB篇,第一章:数据库知识2

    MongDB    数据库知识2 非关系型数据库和关系型数据库的比较1. 不是以关系模型构建数据结构,结构比较自由 不保证数据的一致性2. 非关系型数据库弥补了关系型数据库的一些不足,能 够在处理高并 ...

  10. nginx 重定向与反向代理

    server{    listen       80;    server_name  dianxi.test.net; #将地址重定向为新的ip地址    #rewrite  "^/env ...