我的应用程序接口是用TypeScript/Apollo编写的,我能够在http://localhost:4000/graphql上运行查询/突变。我的前端是Next.js和阿波罗客户端。我使用GraphQL代码生成器来生成所需的客户端代码。
我正在使用:
"@graphql-codegen/cli": "1.20.1",
"@graphql-codegen/typescript": "1.20.2",
"@graphql-codegen/typescript-operations": "1.17.14",
"@graphql-codegen/typescript-react-apollo": "2.2.1",我的codegen.yml文件是
overwrite: true
schema: "http://localhost:4000/graphql"
documents: "src/graphql/**/*.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"我在更改API解析器时运行的脚本是"gen": "graphql-codegen --config codegen.yml"
如果我运行这段代码,我会得到错误:
✖ src/generated/graphql.tsx
Error:
Unable to find any GraphQL type definitions for the following pointers:
- src/graphql/**/*.graphql但是,如果按如下方式设置我的codegen.yml文件,它就可以工作(并且我在其中一个组件中测试了一个查询,我可以访问数据):
overwrite: true
schema: "http://localhost:4000/graphql"
documents:
- "src/graphql/fragments/RecipeSnippet.graphql"
- "src/graphql/fragments/RegularError.graphql"
- "src/graphql/fragments/RegularUser.graphql"
- "src/graphql/fragments/RegularUserResponse.graphql"
- "src/graphql/mutations/createRecipe.graphql"
- "src/graphql/mutations/deleteRecipe.graphql"
- "src/graphql/mutations/login.graphql"
- "src/graphql/mutations/logout.graphql"
- "src/graphql/mutations/register.graphql"
- "src/graphql/mutations/updateRecipe.graphql"
- "src/graphql/queries/me.graphql"
- "src/graphql/queries/recipe.graphql"
- "src/graphql/queries/recipes.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"我不确定我到底做错了什么,更奇怪的是,它曾经是有效的。我看到并尝试了其他一些答案,如this one或this one,但都没有用:(
发布于 2021-02-02 05:47:08
经过反复尝试,我最终从我的计算机上删除了这个项目,再次从repo、yarn install和yarn gen中拉出它。而且它起作用了。去想一想!
https://stackoverflow.com/questions/65996866
复制相似问题