graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

@graphql-mesh/transform-filter-schema prevents creation of index.d.ts

Open leonsomed opened this issue 2 years ago • 2 comments

Describe the bug The command mesh build is unable to generate a type definition file index.d.ts when the transform @graphql-mesh/transform-filter-schema is used to filter queries or mutations generated by the source Open API, Mongoose, and possibly other source handlers. Although, I've noticed that queries or mutations generated via additionalTypeDefs option can be filtered without issues. The bug can be seen when the following transform is added:

transforms:
  - filterSchema:
      mode: bare
      filters:
        - Query.!{getMediaMathFormulaHash}

getMediaMathFormulaHash comes from the Open API source handler. However, that query is not specifically causing the issue, nor the Open API source handler. I've tried a number of combinations of queries and source handlers, and they all seem to experience the same bug. I have also tried with wrap mode and the same issue persists.

To Reproduce Here is a repository with the minimum setup to reproduce the bug https://github.com/leonsomed/graphql-mesh-transform-types-bug.

  • Checkout environment details below to replicate exact conditions (optional)
  • Clone the repo
  • Install dependencies yarn install
  • Build the project yarn build
  • Notice the generated directory .mesh does not contain a type definition file index.d.ts (This is the reported bug)
  • Remove or comment the transform filterSchema from .meshrc.yaml
  • Build the project again yarn build
  • Notice the type definition file index.d.ts is correctly created in directory .mesh

Expected behavior A type definition file index.d.ts should be generated when running mesh build regardless of the transforms or source handlers used.

Environment:

  • OS: macOS Catalina 10.15.4
  • NodeJS: 14.17.0
  • yarn: 1.22.13
  • npm dependencies in package.json

Additional context Since this bug prevents the types from being generated, it is impossible to use the Resolvers type when working with typescript and using the additionalResolvers option.

leonsomed avatar Jan 23 '22 20:01 leonsomed

Sounds similar to https://github.com/Urigo/graphql-mesh/issues/3367

leemhenson avatar Jan 25 '22 14:01 leemhenson

Sounds similar to #3367

I think so yes, though in my use case I do not need to SDK only the types. I read your comment about applying the transform at the source instead of at the root. That was enough to fix my reported issue, which is enough for my use case.

For anyone experiencing the same situation as me, you can apply the transform at the source handler level instead of at the root, like this:

sources:
  - name: Wiki
    handler:
      openapi:
        source: https://api.apis.guru/v2/specs/wikimedia.org/1.0.0/swagger.yaml
        operationIdFieldNames: true
    transforms:
      - filterSchema:
          mode: bare
          filters:
            - Query.!{getMediaMathFormulaHash}

leonsomed avatar Jan 25 '22 20:01 leonsomed

Seems to be fixed in the latest version. Let us know if the issue persists.

ardatan avatar Mar 31 '23 05:03 ardatan