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

File paths in postgraphile handler is not transformed correctly when building for production. (Breaks production build) #3886

Open
MarkLyck opened this issue Apr 29, 2022 · 0 comments

Comments

@MarkLyck
Copy link
Contributor

MarkLyck commented Apr 29, 2022

Describe the bug
When setting up the postgraphile handler using file paths like the below example. It does not translate the file paths when building the production output, and throws errors that modules are not found.

example:

sources:
  - name: crm
    handler:
      postgraphile:
        connectionString: MY_CONNECTION_STRING
        appendPlugins:
          - "@graphile-contrib/pg-simplify-inflector"
          - "./plugins/renameSubscriptionsPlugin"
        options: "./postGraphileOptions.json"
    transforms:
      - encapsulate:
          applyTo:
            query: true
            mutation: true
            subscription: true

This is supposed to load 2 modules, my ./postgraphileOptions.json file and my ./plugins/renameSubscriptionsPlugin file.

Both of these load without any issues when running mesh dev, and the schema also builds fine when running mesh build.

But when running mesh start after running mesh build I get the following error:

(node:31309) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
🕸️ - Server: Generating the unified schema...
🕸️ - crm: Failed to generate the schema
 Error: Cannot find module './plugins/renameSubscriptionsPlugin'.
    at importFn (/Users/marklyck/colony/graphql-mesh/.mesh/index.ts:44180:11)
    at tryImport (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+utils@0.33.5_graphql@16.3.0/node_modules/@graphql-mesh/utils/index.js:72:12)
    at Object.loadFromModuleExportExpression (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+utils@0.33.5_graphql@16.3.0/node_modules/@graphql-mesh/utils/index.js:69:12)
    at /Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+postgraphile@0.20.9_graphql@16.3.0/node_modules/@graphql-mesh/postgraphile/index.js:68:107
    at Array.map (<anonymous>)
    at PostGraphileHandler.getMeshSource (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+postgraphile@0.20.9_graphql@16.3.0/node_modules/@graphql-mesh/postgraphile/index.js:68:83)
    at async /Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:39:28
🕸️ - Server: 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 Object.getMesh (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:69:15)
 ELIFECYCLE  Command failed with exit code 1.

If I remove my custom plugin temporarily the error changes too:

🕸️ - crm: Failed to generate the schema
 Error: Cannot find module './postGraphileOptions.json'.
    at importFn (/Users/marklyck/colony/graphql-mesh/.mesh/index.ts:53420:11)
    at tryImport (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+utils@0.33.5_graphql@16.3.0/node_modules/@graphql-mesh/utils/index.js:72:12)
    at Object.loadFromModuleExportExpression (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+utils@0.33.5_graphql@16.3.0/node_modules/@graphql-mesh/utils/index.js:69:12)
    at PostGraphileHandler.getMeshSource (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+postgraphile@0.20.9_graphql@16.3.0/node_modules/@graphql-mesh/postgraphile/index.js:78:37)
    at async /Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:39:28
🕸️ - Server: 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 Object.getMesh (/Users/marklyck/colony/graphql-mesh/node_modules/.pnpm/@graphql-mesh+runtime@0.33.13_graphql@16.3.0/node_modules/@graphql-mesh/runtime/index.js:69:15)
 ELIFECYCLE  Command failed with exit code 1.

This shows that any file paths set in the postgraphile handler does not seem to work when building for production.

Note: using local file paths works just fine when running mesh dev. It's only when running it in production it fails.

To Reproduce
Add any file path to a postgraphile handler and try to build and start for production.

Expected behavior
The file path should be translated correctly.

I tried to manually go edit the ouputted index.ts file to fix this, and got it working.

since the index.ts imports these as external modules and gives them a set name, I manually tried editing the these 2 lines and got it working:

appendPlugins: [
            "@graphile-contrib/pg-simplify-inflector",
            "./plugins/renameSubscriptionsPlugin",
          ],

should be:

appendPlugins: [
            "@graphile-contrib/pg-simplify-inflector",
            "plugins/renameSubscriptionsPlugin",
          ],

and

options: "./postGraphileOptions.json",

should be:

options: "postGraphileOptions.json",

and then the server will start with no issues when running mesh start

Environment:

  • OS: MacOS
    "@graphile-contrib/pg-simplify-inflector": "^6.1.0",
    "@graphql-mesh/cli": "^0.67.4",
    "@graphql-mesh/graphql": "^0.23.6",
    "@graphql-mesh/openapi": "^0.24.9",
    "@graphql-mesh/postgraphile": "^0.20.9",
    "@graphql-mesh/runtime": "^0.33.13",
    "@graphql-mesh/transform-encapsulate": "^0.3.43",
    "@graphql-mesh/transform-filter-schema": "^0.14.47",
    "@graphql-mesh/transform-prefix": "^0.11.32",
    "@graphql-mesh/transform-rename": "^0.12.33",
    "graphql": "^16.3.0"
  • NodeJS: 18.0.0
@MarkLyck MarkLyck changed the title File paths in postgraphile handler is not transformed correctly when building for production. (Breaking production build) File paths in postgraphile handler is not transformed correctly when building for production. (Breaks production build) Apr 29, 2022
@theguild-bot theguild-bot mentioned this issue Aug 11, 2022
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
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