Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to exclude .d.ts files from documents #1129

Open
4 tasks
ghost opened this issue Sep 1, 2022 · 1 comment
Open
4 tasks

Unable to exclude .d.ts files from documents #1129

ghost opened this issue Sep 1, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 1, 2022

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/cli@2.11.8)
  • NodeJS: v18.8.0

Additional context

@mwahlhuetter
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant