【问题标题】:Why apollo client:codegen is not generate types?为什么 apollo client:codegen 不生成类型?
【发布时间】:2020-06-24 01:58:19
【问题描述】:

我正在尝试获取我的 Apollo 服务器中定义的类型

首先,有效地下载架构:

apollo client:download-schema src/code/queries/schemas/schema.json --endpoint http://localhost:4000/

该命令生成以下 .json,出于演示目的对其进行了缩减。

{
"__schema": {
"queryType": {
  "name": "Query"
},
"mutationType": {
  "name": "Mutation"
},
"subscriptionType": null,
"types": [
  {
    "kind": "OBJECT",
    "name": "Query",
    "description": null,
    "fields": [
      {
        "name": "UserInformation",
        "description": null,
        "args": [],
        "type": {
          "kind": "OBJECT",
          "name": "User",
          "ofType": null
        },
        "isDeprecated": false,
        "deprecationReason": null
      }
    ],
    "inputFields": null,
    "interfaces": [],
    "enumValues": null,
    "possibleTypes": null
  },
  {
    "kind": "OBJECT",
    "name": "User",
    "description": null,
    "fields": [
      {
        "name": "firstName",
        "description": null,
        "args": [],
        "type": {
          "kind": "SCALAR",
          "name": "String",
          "ofType": null
        },
        "isDeprecated": false,
        "deprecationReason": null
      },
      {
        "name": "secondName",
        "description": null,
        "args": [],
        "type": {
          "kind": "SCALAR",
          "name": "String",
          "ofType": null..........

然后将类型生成为打字稿但没有成功:

   apollo client:codegen --target typescript --localSchemaFile src/code/queries/schemas/schema.json  --outputFlat src/code/queries/generated

globalTypes.ts 生成为空(仅 cmets)..

【问题讨论】:

    标签: angular graphql apollo-client codegen


    【解决方案1】:

    您需要包含--includes 选项以指示哪些文件包含要为其生成类型的实际查询。来自docs

    --includes=includes 用于搜索 GraphQL 操作的文件全局。这应该用于查找查询任何客户端架构扩展

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 2019-07-30
      • 2020-01-19
      • 2021-08-29
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      相关资源
      最近更新 更多