Describe the bug
The generated file target is not ignored and leads to duplicate types
If your documents path includes the generated file, like:
overwrite: true
schema: "http://localhost:3001/api/graphql"
generates:
client/src/graphql/types.ts:
documents:
- "client/src/**/*.{ts,tsx}"
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
withComponent: false
withHooks: true
withHOC: false
Then you end up with:
✖ client/src/graphql/types.ts
Not all operations have an unique name
It'd be great if the generated file was automatically excluded.
To Reproduce
Steps to reproduce the behavior:
graphql-codegenExpected behavior
It should work and not error.
Schema/Documents
N/A
Environment:
Additional context
N/A
Fixed in 1.0.4
@dotansimha Did this regress from 1.3.1 to 1.5.0 by any chance?
@rgiese Could you reproduce a repo?
Not readily (it's a bit of a big Lerna-ified monster) but if you can't think of anything obvious that might have caused this, I can try and stand up something isolated.
I'm having something similar when I run the command from circleCi.
On my local machine it runs fine but that could be due to speed.
On the circleCi machine doing my build I'm getting a loop:
Generating schema... 88ms
Saving Prisma Client (TypeScript) at /home/circleci/repo/src/generated/prisma-client
Saving Prisma GraphQL schema (SDL) at /home/circleci/repo/src/generated/schema.graphql
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/generated/gqlTypes.ts
✔ Load GraphQL schemas
⠙ Load GraphQL documents
Generate
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/generated/gqlTypes.ts
✔ Load GraphQL schemas
⠹ Load GraphQL documents
Generate
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/generated/gqlTypes.ts
✔ Load GraphQL schemas
⠸ Load GraphQL documents
Generate
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/generated/gqlTypes.ts
✔ Load GraphQL schemas
⠼ Load GraphQL documents
Generate
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/generated/gqlTypes.ts
✔ Load GraphQL schemas
⠴ Load GraphQL documents
Generate
✔ Parse configuration
❯ Generate outputs
❯ Generate ./src/generated/gqlTypes.ts
✔ Load GraphQL schemas
✖ Load GraphQL documents
...
The relevant part of my config is setup as follows:
schema: ./src/generated/schema.graphql
documents:
- './src/**/*.{ts,tsx}'
- './src/**/*.graphql'
@richardwardza Removing the ./ prefix from documents & the generates key seems to have fixed this for me.
schema: "http://localhost:3000/api/graphql"
generates:
packages/editor/src/graphql.types.tsx:
documents: "packages/editor/src/**/*.{ts,tsx}"
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
@ecoleman @richardwardza I fixed this in: https://github.com/dotansimha/graphql-code-generator/commit/a38a82e845d1b5e66643e3307dca7d540d8e7b19 . will be available in the next release.
@dotansimha Hi, we just noticed in our team that the above fix is working on UNIX systems (generated file is ignored) but not on Windows machines.
Thanks @smajl , I fixed it in graphql-toolkit :)
Fixed in 1.7.0
Most helpful comment
@ecoleman @richardwardza I fixed this in: https://github.com/dotansimha/graphql-code-generator/commit/a38a82e845d1b5e66643e3307dca7d540d8e7b19 . will be available in the next release.