graphql-mesh
graphql-mesh copied to clipboard
fix: Corerct TS artifact generation when Mesh config is in TS/JS format
π¨ IMPORTANT: Please do not create a Pull Request without creating an issue first.
Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes #5965
Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
Screenshots/Sandbox (if appropriate/relevant):
Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- A unit test was provided, in which Mesh configuration files with
.ts
extension are processed with the Mesh build command and then it's checked that the extension of the Mesh configuration files is replaced to.js
.
Test Environment:
- OS:
-
@graphql-mesh/...
: - NodeJS:
Checklist:
- [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests and linter rules pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
Important note
In order to be able to test the CLI commands in the packages/cli/test/cli.spec.ts
test suite, I needed to generate the config schema in the GitHub test workflow file (.github/workflows/tests.yml
).
π¦ Changeset detected
Latest commit: 08a2319e598f2a22153d95a3b40282ec7013a67a
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 48 packages
Name | Type |
---|---|
@graphql-mesh/cli | Patch |
auth0-example | Patch |
cloudflare-workers | Patch |
example-fastify | Patch |
example-gcp | Patch |
graphql-file-upload-example | Patch |
grpc-example | Patch |
grpc-reflection-example | Patch |
hasura-openbrewery-geodb | Patch |
hello-world-esm | Patch |
json-schema-hello-world | Patch |
covid-mesh | Patch |
json-schema-example | Patch |
json-schema-fhir | Patch |
json-schema-file-upload | Patch |
json-schema-subscriptions | Patch |
mongoose-example | Patch |
mysql-employees | Patch |
mysql-rfam | Patch |
neo4j-example | Patch |
nextjs-apollo-example | Patch |
nextjs-sdk-example | Patch |
odata-microsoft-graph-example | Patch |
odata-msgraph-programmatic-ts | Patch |
odata-msgraph-programmatic | Patch |
odata-trippin-example | Patch |
javascript-wiki | Patch |
typescript-location-weather-example | Patch |
openapi-meilisearch | Patch |
openapi-orbit | Patch |
openapi-stackexchange | Patch |
openapi-stripe | Patch |
openapi-subscriptions | Patch |
openapi-youtrack | Patch |
openwhisk-example | Patch |
postgres-geodb-example | Patch |
programmatic-batching-example | Patch |
reddit-example | Patch |
country-info-example | Patch |
soap-demo | Patch |
soap-netsuite | Patch |
spacex-cfw | Patch |
chinook | Patch |
thrift-calculator | Patch |
type-merging-batching-example | Patch |
federation-supergraph-gateway | Patch |
federation-gateway | Patch |
gateway-example | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
@gilgardosh Just pushed a commit with the requested changes. Thank you for the review!
Hi @ardatan and @gilgardosh, I wanted to ask whether the fix proposed in this PR is still relevant.
I also wanted to mention that after pushing the latest changes requested by @gilgardosh, I got many test suites failing with many random errors. It looks like the build job should be re-triggered but I cannot do that myself due to permissions.
Thank you very much in advance for your time!
Hey, great work @cweckesser! This would solve some issues that we are facing in our project π€©
@ardatan @gilgardosh Any chance this can be reviewed and merged any time soon? Thanks π
@ardatan I updated my PR from the latest changes in master (the cli
package was moved to legacy). In addition, all my tests are green now.
If you still consider these changes relevant, I'd appreciate it if you could help me with a review.
Thanks this is looking good!
That change seems to broke graphql mesh on our side:
β $ mesh start β
β πΈ Mesh π₯Error: Cannot find module './../.meshrc.js' β
β Require stack: β
β - /app/.mesh/index.ts β
β - /app/node_modules/@graphql-mesh/utils/cjs/defaultImportFn.js β
β - /app/node_modules/@graphql-mesh/utils/cjs/index.js β
β - /app/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js β
β - /app/node_modules/@graphql-mesh/runtime/cjs/index.js β
β - /app/node_modules/@graphql-mesh/cli/cjs/index.js β
β - /app/node_modules/@graphql-mesh/cli/cjs/bin.js β
β at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15) β
β at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/app/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30) β
β at Function.Module._load (node:internal/modules/cjs/loader:986:27) β
β at Module.require (node:internal/modules/cjs/loader:1233:19) β
β at require (node:internal/modules/helpers:179:18) β
β at Object.<anonymous> (/app/.mesh/index.ts:30:1) β
β at Module._compile (node:internal/modules/cjs/loader:1358:14) β
β at Module.m._compile (/app/node_modules/ts-node/src/index.ts:1618:23) β
β at Module._extensions..js (node:internal/modules/cjs/loader:1416:10) β
β at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:1621:12)
Could you create a new issue with a reproduction by any chance? Thanks!
Sure.
https://github.com/Warxcell/mesh-ts-reproducible/
@Warxcell in the initial issue it was reported that the mesh build
command would generate the index.ts
file under the .mesh
folder with a reference to the .meshrc.ts
file. This worked well when running the mesh build
& mesh start
commands in tandem, but if the project were to be compiled with the TS compiler, then the generated index.js
file would keep the reference to the .meshrc.ts
file. And since the .meshrc.ts
file would also be compiled, then the index.js
file would be pointing to the incorrect file in the compilation output folder.
I think a potential solution to this issue could be adding a parameter to the mesh build
command, for instance --production
. Running mesh build
with that flag could make the logic I implemented kick in, replacing the reference to .meshrc.ts
with .meshtc.js
in the index.ts
file. @ardatan if you think this solution could work, then I volunteer to implement it.
I don't compile TS to JS, I run mesh start directly with TS.
I tried also giving explicitly --fileType ts
.
--fileType [string] [choices: "json", "ts", "js"] [default: "ts"]
Can't we use this fileType ?
@Warxcell can you try:
@graphql-mesh/cli@0.91.0-alpha-20240620123302-b0b8c297177208f5e5378cf7da64c3220c4a9c0c
from #7131. Thanks!
Now its broken when schema is TS file, like
const config: Config = {
"sources": [
{
"name": "Name",
"handler": {
"graphql": {
"source": "src/schema.ts",
"batch": true
}
}
}
],
};
$ mesh start β
β πΈ Mesh π‘Starting GraphQL Mesh... β
β πΈ Mesh π‘Serving GraphQL Mesh: http://0.0.0.0:4000 β
β πΈ Mesh - Cms π₯Failed to generate the schema for the source "Name" β
β Cannot find module 'src/schema.ts'. β
β Mesh HTTP π₯ Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh. β
β at getMesh (/app/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:124:15)
I've made a fix for schema imports. @Warxcell can you please try this version and report back
@graphql-mesh/cli@0.91.0-alpha-20240624143443-f3d91f7bc44d05a54a1c3b6cfe8a9b24c670681e
Thanks in advance!
I've made a fix for schema imports. @Warxcell can you please try this version and report back
@graphql-mesh/cli@0.91.0-alpha-20240624143443-f3d91f7bc44d05a54a1c3b6cfe8a9b24c670681e
Thanks in advance!
Works like charm. Thanks! :heart:
@Warxcell we've just cut a new stable version. You can upgrade to @graphql-mesh/[email protected]
. π
@enisdenjo
Encountered a similar issue, but after upgrading the CLI to version 0.91.2
, a new problem came up when using additionalEnvelopPlugins
:
Mesh π₯ TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /xxx/mesh/src/config/plugins.ts
at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
at new NodeError (node:internal/errors:372:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:76:11)
at defaultGetFormat (node:internal/modules/esm/get_format:118:38)
at defaultLoad (node:internal/modules/esm/load:21:20)
at ESMLoader.load (node:internal/modules/esm/loader:407:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:326:22)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:345:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:304:34)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
at Object.getMeshOptions (/xxx/mesh/.mesh/index.ts:2564:42)
at async Object.handler (/xxx/mesh/node_modules/@graphql-mesh/cli/cjs/index.js:190:33)
Reproducible link: https://github.com/jltxwesley/mesh-test/tree/main (mesh dev
works, mesh start
is broken under node 16
and 18
)
hey @jltxwesley, Node 18 (and later) works for me:
$ node -v
v18.20.4
$ npm -v
10.7.0
$ npm i
β
$ npm run build
β
$ npm run start
πΈοΈ Mesh π‘ Serving GraphQL Mesh: http://0.0.0.0:4000 in 24 forks
[...]
β
But I can confirm that Node 16 does not work. However, since Node 16 is not maintained anymore, we might just bump the least required node engine for the CLI. Do you have a use-case where you need Node 16?
@enisdenjo Interestingly, it works on Node 18.20.4, but not on Node 18.18.2.
Another issue I found is that if I bump CLI to version ~0.92.4 (the latest version), both npm run dev
and npm run start
are broken on Node 20.
@jltxwesley I've fixed the dev and start issues in v0.92.6, but the build is still generating incorrect artifacts - a fix for that is coming soon. I'll keep you posted.
@enisdenjo is that going to fix the issue with generating correct paths to additionalEnvelopPlugins and customFetch?
- currently if additionalEnvelopPlugins is ts output extension is js
- customFetch on windows path is ..\src\custom-fetch.ts -> not found
hey @trylas, you can try the latest stable release @graphql-mesh/[email protected]
. If it still does not work, please open an issue ideally with a reproduction. Thanks!