graphql-query-rewriter 是一个graphql schema 变动重写的中间件,可以帮助我们解决在版本变动,查询实体变动
是的问题,从目前已知的技术中我们可选的方案有以下处理变动的

  • directive (client、server 端指令)
  • query rewrite (schema 重写)
  • prisma middleware (中间件模型)

参考demo

  • 安装
 
npm install graphql-query-rewriter express-graphql-query-rewriter
  • 代码
import { FieldArgTypeRewriter } from 'graphql-query-rewriter';
import { graphqlRewriterMiddleware } from 'express-graphql-query-rewriter';
const app = express();
// set up graphqlRewriterMiddleware right before graphQL gets processed
// to rewrite deprecated queries so they seamlessly work with your new schema
app.use('/graphql', graphqlRewriterMiddleware({
  rewriters: [
    new FieldArgTypeRewriter({
      fieldName: 'userById',
      argName: 'id',
      oldType: 'String!',
      newType: 'ID!'
    }),
  ]
}));​
app.use('/graphql', graphqlHTTP( ... ));
 

说明

当看graphql-query-rewriter 有一些限制

  • 只能对于那个query 进行单独处理
  • 不支持别名字段的处理

参考资料

https://github.com/ef-eng/graphql-query-rewriter

graphql-query-rewriter 无缝处理graphql 变更的更多相关文章

  1. SpringBoot开发秘籍 - 集成Graphql Query

    概述 REST作为一种现代网络应用非常流行的软件架构风格受到广大WEB开发者的喜爱,在目前软件架构设计模式中随处可见REST的身影,但是随着REST的流行与发展,它的一个最大的缺点开始暴露出来: 在很 ...

  2. [GraphQL] Use Arguments in a GraphQL Query

    In GraphQL, every field and nested object is able to take in arguments of varying types in order to ...

  3. 爬取LeetCode题目——如何发送GraphQL Query获取数据

    前言   GraphQL 是一种用于 API 的查询语言,是由 Facebook 开源的一种用于提供数据查询服务的抽象框架.在服务端 API 开发中,很多时候定义一个接口返回的数据相对固定,因此要获得 ...

  4. GraphQL介绍&使用nestjs构建GraphQL查询服务

    GraphQL介绍&使用nestjs构建GraphQL查询服务(文章底部附demo地址) GraphQL一种用为你 API 而生的查询语言.出自于Facebook,GraphQL非常易懂,直接 ...

  5. 使用lua graphql 模块让openresty 支持graphql api

      graphql 是一个很不错的api 查询标准语言,已经有一个lua 的版本支持graphql 项目使用docker&&docker-compose 运行 环境准备 模块安装 lu ...

  6. [GraphQL] Query a GraphQL API with graphql-request

    To query a GraphQL API, all you need to do is send an HTTP request that includes the query operation ...

  7. [GraphQL] Query Lists of Multiple Types using a Union in GraphQL

    Unions are used when we want a GraphQL field or list to handle multiple types of data. With a Union ...

  8. [GraphQL] Query GraphQL Interface Types in GraphQL Playground

    Interfaces are similar to Unions in that they provide a mechanism for dealing with different types o ...

  9. [GraphQL] Query Local and Remote Data in Apollo Link State

    In this lesson, you will learn how to query local and remote data in Apollo Link State in the same c ...

随机推荐

  1. RabbitMq 概述

    RabbitMQ是实现了高级消息队列协议(Advanced Message Queueing Protocol , AMQP)的开源消息代理软件(亦称面向消息的中间件). 1.AMQP协议 Rocke ...

  2. Bitnami配置域名访问

    安装完成Bitnami后,需要执行以下命令将默认目录改为/wordpress: E:\Bitnami\wordpress-5.2.2-0\apps\wordpress\bnconfig.exe --a ...

  3. PHP获取前台传过来的时间年份,进行处理。

    在做时间区间用到一个方法,以方便在数据库中用in()的使用,这个是我同事给我的,我先保存好,以后还可以的用到. /*处理起终年月,返回中间的月份以供数据库查询使用 * @param $yearl 起始 ...

  4. nodejs的交互式解释器模式常用命令

    node - 进入交互器交互器解释模式 ctrl + c - 退出当前终端 ctrl + c 按下两次 - 退出 Node REPL ctrl + d - 退出 Node REPL 向上/向下 键 - ...

  5. NETRemoting学习笔记

    1..NET Remoting概念 1.一种分布式处理方式.从字面意义上看出,他是基于.net平台的一种远程对象开发技术,该技术是将远程计算机中的数据视为分布式对象来进行开发. 2.一种网络通信技术. ...

  6. 洛谷【P1048 采药】题解

    题目链接 分析:典型的01背包问题,设dp[i][j]为空间(也就是题面中的时间)是j的背包在装前i个物品(草药)所得的最大价值,v[i]为第i个物品的重量(采药的时间),w[i]为第i个物品(草药) ...

  7. sdcard不可执行.

    Possibly you placed it on your sdcard -- which is mounted with the noexec flag. You either need to m ...

  8. ES6 新增集合----- Set 和Map

    Sets 和数组一样,都是一些有序值的的集合,但是Sets 和数组又有所不同,首先Sets 集合中不能存有相同的值,如果你向Sets 添加重复的值,它会忽略掉, 其次Sets 集合的作用也有所不同,它 ...

  9. 【故障解决】ORA-06502错误解决

    [故障解决]ORA-06502: PL/SQL: numeric or value error: character string buffer too small 一.1  BLOG文档结构图   ...

  10. JSON是什么

    JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度, 那么,JSON到底是什么? JSON就是一串字符串 只不过元素会使 ...