Apollo codegen:generate 给出错误“使用‘typescript’目标生成查询文件”

Mar*_*uck 4 typescript apollo reactjs graphql react-apollo

我在 Express 上有 Apollo Graph 的后端。

在我的客户端 React 应用程序中,我下一步要做的是:

apollo codegen:generate --excludes=node_modules/* --includes=**/*.tsx --target typescript --tagName gql --outputFlat generate
Run Code Online (Sandbox Code Playgroud)

我等待生成文件夹,但此命令给出了下一个错误:

Error: There are multiple definitions for the herewas operation. 
All operations in a project must have unique names. 
If generating types, only the types for the first definition 
found will be generated.at GraphQLClientProject.checkForDuplicateOperations 
(....\node_modules\apollo\node_modules\apollo-language-server\lib\project\base.js:129:31)
.........
.........
Generating query files with 'typescript' target
> Apollo does not support anonymous operations
Run Code Online (Sandbox Code Playgroud)

我还有 apollo.config.js:

module.exports = {
  client: {
    service: {
      url: "http://localhost:4000/graphql"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我不明白在哪里挖掘,代码来自谷歌搜索

小智 6

Apollo不支持匿名操作

您应该为您的查询/变异操作命名:

这将起作用:

query SOME_NAME {
  users {
    age
  }
}
Run Code Online (Sandbox Code Playgroud)

这将不起作用(请注意,缺少查询名称):

query {
  users {
    age
  }
}
Run Code Online (Sandbox Code Playgroud)

您也可以检查此线程: https ://github.com/apollographql/apollo-tooling/issues/184