graphql config支持多个schema

前言

由于重构或者不同服务等各种需求,一个前端应用需要多个schema ,连接多个不同的graphql后端,下面是如何配置。

1. .graphqlconfig文件

这里是配置webstrom graphql 插件 文档地址: https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/

{
  "projects": {
    "fe": {
      "schemaPath": "schema.graphql",
      "extensions": {
        "endpoints": {
          "Default GraphQL Endpoint": {
            "url": "...", // 这里是第一个graphql后端服务地址
            "introspect": true
          }
        }
      },
      "includes": [
        "src/app/graphql/{yara,snort}/*.graphql" // 这里是第一个graphql后端服务地址对应的graphql 文件目录
      ]
    },
    "antiy-feature-flow-fe-bff": {
      "schemaPath": "schema-bff.graphql",
      "extensions": {
        "endpoints": {
          "url": "....", // 这里是第二个graphql后端服务地址
          "introspect": true
        }
      },
      "includes": [
        "src/app/graphql/avlfd/*.graphql" // 这里是第二个graphql后端服务地址对应的graphql 文件目录
      ]
    }
  }
}


2. codegen.yaml 文件

这里是配置GraphQL Code Generator 地址: https://graphql-code-generator.com/docs/getting-started/index

generates:
  src/app/graphql/generated/graphql.ts: # 这里是第一个graphql后端服务地址对应的graphql,生成的代码目录
    schema: "./schema.graphql"  # 这里是第一个graphql后端服务地址对应schema文件
    documents: "src/**/{snort,yara}/*.graphql"
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-apollo-angular"
#      - "typescript-graphql-files-modules"
#      - "typescript-document-nodes"
#      - "fragment-matcher"
  src/app/graphql/generated/graphql-bff.ts:  # 这里是第二个graphql后端服务地址对应的graphql,生成的代码目录
    schema: "./schema-bff.graphql"   # 这里是第二个graphql后端服务地址对应schema文件
    documents: "src/**/avlfd/*.graphql"
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-apollo-angular"
  #      - "typescript-graphql-files-modules"
  #      - "typescript-document-nodes"
  #      - "fragment-matcher"

最后

最后生成的效果 代码目录如下
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值