ardatan / graphql-mesh

🕸️ GraphQL Federation Framework for any API services such as REST, OpenAPI, Swagger, SOAP, gRPC and more...
https://the-guild.dev/graphql/mesh
MIT License
3.26k stars 334 forks source link

Build command not generate JS file types correctly with commonjs #5343

Open diegoarda opened 1 year ago

diegoarda commented 1 year ago

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.


Describe the bug

When we launch build command of the cli with commonjs and the flag --fileType=js

mesh build --fileType=js

the build commands fails because it are not treating files as commonjs library. Moreover, without fileType=js it only generates ts files and is not traspiling to js files.

To Reproduce Steps to reproduce the behavior:

  1. In the repository, change build command to mesh build --fileType=js
  2. Execute npm run build
  3. Launch the next error:

💥 🕸️ Mesh - Wiki Failed to generate the schema C:\Inditex\Projects\mesh\openapi-javascript-wiki.mesh\sources\Wiki\schemaWithAnnotations.js:2 import { buildASTSchema } from 'graphql'; ^^^^^^

SyntaxError: Cannot use import statement outside a module at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1195:20) at Module._compile (node:internal/modules/cjs/loader:1239:27) at Module._extensions..js (node:internal/modules/cjs/loader:1329:10) at Object.require.extensions. [as .js] (C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules\ts-node\src\index.ts:1608:43) at Module.load (node:internal/modules/cjs/loader:1133:32) at Function.Module._load (node:internal/modules/cjs/loader:972:12) at Module.require (node:internal/modules/cjs/loader:1157:19) at require (node:internal/modules/helpers:119:18) at C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules\@graphql-mesh\utils\cjs\defaultImportFn.js:29:74 💥 🕸️ Mesh Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 environmental variable to get more verbose output. at getMesh (C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules\@graphql-mesh\runtime\cjs\get-mesh.js:167:15) at async Object.handler (C:\Inditex\Projects\mesh\openapi-javascript-wiki\node_modules\@graphql-mesh\cli\cjs\index.js:311:53)

Expected behavior

Generate correct commonjs package with js files (not only TS files).

Environment:

Additional context

It happens with other samples of commonjs. It seems that schemaWithAnnotations.js file is not treated correctly as commonjs file and it treats it as ESM module.

gabel commented 3 months ago

@diegoarda its been some time but did you find any workaround on that one?

diegoarda commented 3 months ago

@gabel finally we didn't work with Graphql and I left the use of the library aside. I'm sorry :(