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

cli fails generating artifacts #4562

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

cli fails generating artifacts #4562

santino opened this issue Sep 21, 2022 · 1 comment

Comments

@santino
Copy link
Contributor

santino commented Sep 21, 2022

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions 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
Since the release of v0.78.12 the cli package has an issue that causes a failure on generating the Typescript artifacts.
This happens when working with a single data source and a transform in wrap mode.
This is the output:

💡 🕸️  Mesh Generating the unified schema
💡 🕸️  Mesh - Source1 Dereferencing the bundle
💡 🕸️  Mesh - Source1 Creating the GraphQL Schema from dereferenced schema
💡 🕸️  Mesh Generating artifacts
💡 🕸️  Mesh Generating index file in TypeScript
💥 🕸️  Mesh TypeError: Cannot read properties of undefined (reading 'get')
    at generateTsArtifacts (/Users/user/projects/mesh-project/node_modules/@graphql-mesh/cli/bin.js:251:70)
    at Object.handler (/Users/user/projects/mesh-project/node_modules/@graphql-mesh/cli/bin.js:1033:19)

To Reproduce
Steps to reproduce the behavior:

  • Have a Mesh service that works on a single data source (hence no stitching required)
  • Define a transform at the source level that supports both bare and wrap mode (e.g. naming convention, filterSchema, etc.)
  • Omit the mode property in the transform config (or set it to wrap)
  • Run the server

Expected behavior
The artifacts are generated correctly and the server runs as normal.

@santino
Copy link
Contributor Author

santino commented Sep 21, 2022

Hey @ardatan, I thought I'd summarise my findings on this issue.

This happens because merger-bare is applied by default, at the root level, to the Mesh Config.
Merger-bare does not seem to play nice when used in a single data source (no merging actually required) and at least one wrap mode transform.
In a scenario like this, merger-stitching should be user as a default instead; so this seems to be the first thing to fix.
In fact, if I explicitly apply merger: stitching to the Mesh Config .yaml file, things work again as expected.

Clearly, this is just the initial part of the issue, because developers might still need to user merger: bare and it should just work.

The actual error is generated by generateTsArtifacts which expects a unified schema as first argument.
Then it tries to access the get property out of unifiedSchema.extensions.sourceMap, like this:

const transformedSchema = unifiedSchema.extensions.sourceMap.get(rawSource);

The problem, in this case, is that with this configuration (single data-source with merger-bare and wrap-mode transform) the extensions property in the unified schema resolves to [Object: null prototype] {} and so the sourceMap property is undefined.
Instead, in the case of a single source with merger-bare and bare-mode transform, the same extensions property does have sourceMap.get and so generateTsArtifacts can get the transformedSchema.

Hope this helps.

This was referenced Apr 30, 2024
This was referenced May 7, 2024
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