生成类型产生的空文件

问题描述:

我拿these steps,这意味着,我首先创建JSON:生成类型产生的空文件

apollo-codegen introspect-schema schema.graphqls --output schema.json 

这将产生:

{ 
    "data": { 
    "__schema": { 
     "queryType": { 
     "name": "Query" 
     }, 
     "mutationType": null, 
     "subscriptionType": null, 
     "types": [ 
     { 
      "kind": "OBJECT", 
      "name": "Query", 
      "description": "", 
      "fields": [ 
      { 

       ... 

但之后,当我运行:

apollo-codegen generate **/*.graphqls --schema schema.json --target typescript --output schema.ts 

我得到一个空的schema.ts类型文件:

/* tslint:disable */ 
// This file was automatically generated and should not be edited. 
/* tslint:enable */ 

想法?

在您的apollo-codegen generate行中,您的目标文件为.graphl*s*。应该是.graphql

您期望生成器匹配哪个文件?它需要包含针对您的模式运行的查询或突变的文件 - 它不会为模式本身生成代码:

此命令的目的是为查询和变异操作生成类型针对模式(它不会为模式本身生成类型)。

来源:https://www.apollographql.com/docs/angular/features/developer-tooling.html#introspect