zoukankan      html  css  js  c++  java
  • 使用merge-graphql-schemas 进行graphql schema 以及resovler 合并

    merge-graphql-schemas 是一个方便的工具,可以进行schema 以及resovler 的合并处理

    一个schema 合并参考demo

    • schema 定义
    // ./graphql/types/clientType.js
    export default `
      type Client {
        id: ID!
        name: String
        age: Int
        products: [Product]
      }
      type Query {
        clients: [Client]
        client(id: ID!): Client
      }
      type Mutation {
        addClient(name: String!, age: Int!): Client
      }
    `;
    // ./graphql/types/productType.js
    export default `
      type Product {
        id: ID!
        description: String
        price: Int
        client: Client
      }
      type Query {
        products: [Product]
        product(id: ID!): Product
      }
    `;
    • 合并
    // ./graphql/types/index.js
    import { mergeTypes } from 'merge-graphql-schemas';
    import clientType from './clientType';
    import productType from './productType';
    const types = [
      clientType,
      productType,
    ];
    // NOTE: 2nd param is optional, and defaults to false
    // Only use if you have defined the same type multiple times in
    // different files and wish to attempt merging them together.
    export default mergeTypes(types, { all: true });

    说明

    如果在早期项目规划schema 约定还是比较好的时候merge-graphql-schemas 还是一个不错的方案
    同时已经好好多解决方案了,apollo 团队的联邦还是很不错的,使用此功能,我们可以方便的进行graphql
    api 聚合,如果对于后端约定比较好的,做为graphql gateway 的一个工具也是不错的

    参考资料

    https://github.com/Urigo/merge-graphql-schemas

  • 相关阅读:
    codeblocks基本调试方法—gdb—Debugger
    五大开源Web服务器
    【u237】分数化小数
    【u230】回文词
    【t099】最接近神的人
    【t052】冰岛
    【t069】奇怪的迷宫
    【p092】分数线划定
    【u243】拓扑排序
    【u247】生物进化
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/11070687.html
Copyright © 2011-2022 走看看