"Not all operations have an unique name" error with "near-operation-file" preset
See original GitHub issueDescribe the bug
I am using the ‘near-operation-file’ preset to generate types next to the files that have the GraphQL operations. When I try to generate the types again though I get the “Not all operations have an unique name” error, presumably because the generated types are not ignored.
To Reproduce Steps to reproduce the behavior:
- Use the following config with a query in a
.tsfile. - Generate the types using
@graphql-codegen. - Generate the types again.
My codegen.yml config file:
overwrite: true
schema: 'http://localhost:24000/graphql'
documents:
- './pages/**/*.{ts,tsx}'
- './components/**/*.{ts,tsx}'
generates:
./generated/graphql/types.ts:
plugins:
- 'typescript'
./:
preset: 'near-operation-file'
presetConfig:
extension: '.gql.types.tsx'
baseTypesPath: 'generated/graphql/types.ts'
plugins:
- 'typescript-operations'
- 'typescript-react-apollo'
config:
withHooks: true
hooks:
afterAllFileWrite:
- prettier --write
Expected behavior
It should work and not error.
Environment:
- OS: macOS 10.14.5
@graphql-codegen: 1.8.3- Node: 11.10.1
Additional context
Similar issues I could find:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
near-operation-file-preset - GraphQL Code Generator
This preset generates a file per each operation file. Example. In order to use this preset, you need to add 2 outputs to...
Read more >@graphql-codegen/near-operation-file-preset - npm
GraphQL Code Generator preset for generating operation code near the operation file. ... This package does not have a README.
Read more >Graphql - what constitutes an operation having a unique name?
I am having trouble making my code generator run. The reason given is that Not all operations have an unique name: AllIssueGroups.
Read more >graphql-code-generator - Bountysource
We are receiving an error when generating our types from graphql (via gatsby) that ... Graphql Schemas provide everything we need to generate...
Read more >How I start a GraphQL app with Slash GraphQL - Dgraph Blog
GraphQL isn't coming into it until I have something to iterate on. ... @graphql-codegen/add @graphql-codegen/near-operation-file-preset.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This was already fixed, but in your use case, you are loading the documents on the root level, and it causes validation to run while generating the
./generated/graphql/types.tsbase file.You should do something like that:
If it’s in the root level, then while running
generated/graphql/types.ts, it causes it to pass documents (and it’s not necessary there, build it checks it anyway because of the current plugins architecture).@vasilak
@syahmiyani Try to use more specific glob patterns like *.graphql.ts etc