Describe 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:
.ts file.@graphql-codegen.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:
@graphql-codegen: 1.8.3Additional context
Similar issues I could find:
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.ts base file.
You should do something like that:
overwrite: true
schema: 'http://localhost:24000/graphql'
generates:
./generated/graphql/types.ts:
plugins:
- 'typescript'
./:
preset: 'near-operation-file'
documents:
- './pages/**/*.{ts,tsx}'
- './components/**/*.{ts,tsx}'
presetConfig:
extension: '.gql.types.tsx'
baseTypesPath: 'generated/graphql/types.ts'
plugins:
- 'typescript-operations'
- 'typescript-react-apollo'
config:
withHooks: true
hooks:
afterAllFileWrite:
- prettier --write
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
Hmm, OK, so I have to add it for every task separately.
Sounds good, thanks for looking into it 馃憤
I found what cousing this problem on my end , documents: "./src/**/*.{tsx,ts}" , I include everything including the already exist generated types , to be look and generate . Either delete the generated types file everytime running codegen or modify the config to exlude the generated type like this documents: "./src/**/!(*.types).{tsx,ts} would solve this issue. My generated types file look something like this "types.type.tsx".
@syahmiyani Try to use more specific glob patterns like *.graphql.ts etc
Most helpful comment
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