graphql-config
graphql-config copied to clipboard
Unable to exclude .d.ts files from documents
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generate
in the terminal.Please make sure the Codegen and plugins version under
package.json
matches yours. - [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
I am attempting to write a graphql config that will auto-generate typescript code based on embedded gql templates in .ts files.
I have found a bug that is caused by .d.ts
(typescript type definitions files) also being included in the documents glob.
To Reproduce Steps to reproduce the behavior:
Use a configuration that includes .ts files. In this example, a .d.ts file may exist in src/global.d.ts
.
---
projects:
jellybean:
schema: schema.graphql
documents:
- src/**/*.jellybean.{graphql,gql}
- src/**/*.tsx
- src/**/*.ts
extensions:
codegen:
generates:
generated-api.ts:
plugins:
- typescript
- typescript-operations
- typescript-react-query
This config errors with:
Could not parse the TypeScript file at src/global.d.ts to extract the graphql tags SyntaxError: Unexpected token (3:28)
Things I have tried:
- Adding a documents entry:
"!(**/*.d.ts)"
- Adding the negation in the document rule itself:
src/**/!(.d)*.ts
- Adding an exclude entry under jellybean, e.g.
exclude: "**/*.d.ts"
- Adding an absolute path to the file that needs to be excluded. e.g.
exclude: 'src/global.d.ts'
All of these have had no effect and .d.ts files are always included. I can only fix it by removing the src/**/*.ts
entry.
Expected behavior
.d.ts
files should be excluded and everything should work like magic.
Environment:
- OS: macOS 12.5.1 (x86_64)
- GraphQL Config Version: 4.3.5 (via
@graphql-codegen/[email protected]
) - NodeJS: v18.8.0
Additional context
Im experiencing the same issue, but I'm trying to exclude a local schema definition thats in a .graphql
file.
Had no luck getting the file excluded trying the same things that @onthecais tried..
The reason I tried excluding the local schema is because it overrides a field with another type, which causes the error Error: Field "Foo.Bar" already exists in the schema. It cannot also be defined in this type extension.
.
Using graphql-codegen with a separate codegen.yaml
file I worked around this issue using the ignoreFieldConflicts: true
config parameter, because there I need to have this schema information included, successfully creating all my queries, mutations, types and so on.
But I could not get my vscode graphql extension to work again, because I can not exclude the local schema file, which I don't need for intellisense in my IDE.