graphql-mesh
graphql-mesh copied to clipboard
Rename and replace-field transforms on graphql source alone break the CLI
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [x] 1. The issue provides a reproduction available on
https://codesandbox.io/p/devbox/polished-water-d96hms?file=%2Fpackage.json%3A7%2C25
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
Running the repo shows it failing right away.
Describe the bug
I want to rename the field txName in the Treatment type to name and make it non nullable. Effectively going from:
type Treatment {
txName: String
}
to:
type Treatment {
name: String!
}
I used the rename and replace fields together at the source level and the transform seems to work as expected because the resulting schema looks the way I want it.
However, when I run the CLI with mesh dev it fails with the following error:
🕸️ Mesh - Server 💡 Starting GraphQL Mesh...
🕸️ Mesh - Server 💡 Serving GraphQL Mesh: http://0.0.0.0:4000
Transformed schema is not set yet. Returning a dummy one.
🕸️ Mesh 💡 Generating index file in TypeScript
🕸️ Mesh 💥 An error occurred while building the artifacts: TypeError: Cannot read properties of undefined (reading 'get')
at generateTsArtifacts (/Users/dario/mesh-test/node_modules/@graphql-mesh/cli/cjs/commands/ts-artifacts.js:113:70)
at /Users/dario/mesh-test/node_modules/@graphql-mesh/cli/cjs/index.js:131:63
If I use the transforms separately the error is gone. The order of the transforms doesn't matter.
What I noticed is that unifiedSchema.extensions
is an empty object in @graphql-mesh/cli/cjs/commands/ts-artifacts.js
. Not sure why it could end up like that?
To Reproduce Steps to reproduce the behavior:
Running the repo shows it failing.
Expected behavior
It should apply the transform as expected.
Environment:
- OS: macOS 14.4.1 (23E224) (local)/on codesanbox it's whatever it uses
- "@graphql-mesh/cli": "0.89.9",
- "@graphql-mesh/graphql": "^0.97.5",
- "@graphql-mesh/json-schema": "0.99.6",
- "@graphql-mesh/transform-rename": "^0.97.5",
- "@graphql-mesh/transform-replace-field": "^0.97.5",
- NodeJS: v18.16.0 (local)/v20.12.0 (codesandbox)
Additional context
When I forked the sample project on Codesandbox, I saw it had a jsonschema source on it. I went ahead and added my code after the jsonschema source and to my surprise it worked! So if you uncomment the json schema it won't complain. I'm using that as a workaround for now.
Thanks!