GraphQL error on Vercel deploy (Redwood 6.1.0)

Hi here,

I tried to deploy my RW app (dbAuth) on Vercel following the tutorial.
The deploy is running well but when try to use the live app, but it not works…

I checked the console and i constate that when i signin or signup, i can see in console/network that the graphql auth request is ok, but the getCurrentUser graphql request not works, so the app si not usable.
In the console, for this request, the payload is

{"query":"query __REDWOOD__AUTH_GET_CURRENT_USER { redwood { currentUser } }"}

and returns the 500 error with : FUNCTION_INVOCATION_FAILED

So i checked the vercel logs and get this error:

{
  "Invoke Error": {
    "errorType": "Error",
    "errorMessage": "Cannot find module '../lib/generateGraphiQLHeader'\nRequire stack:\n- /var/task/api/dist/functions/graphql.js\n- /var/task/___vc/__launcher.js\n- /var/runtime/index.mjs",
    "code": "MODULE_NOT_FOUND",
    "requireStack": [
      "/var/task/api/dist/functions/graphql.js",
      "/var/task/___vc/__launcher.js",
      "/var/runtime/index.mjs"
    ],
    "stack": [
      "Error: Cannot find module '../lib/generateGraphiQLHeader'",
      "Require stack:",
      "- /var/task/api/dist/functions/graphql.js",
      "- /var/task/___vc/__launcher.js",
      "- /var/runtime/index.mjs",
      "    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)",
      "    at Module._load (node:internal/modules/cjs/loader:922:27)",
      "    at Module.require (node:internal/modules/cjs/loader:1143:19)",
      "    at require (node:internal/modules/cjs/helpers:110:18)",
      "    at Object.<anonymous> (/var/task/api/dist/functions/graphql.js:47:45)",
      "    at Module._compile (node:internal/modules/cjs/loader:1256:14)",
      "    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)",
      "    at Module.load (node:internal/modules/cjs/loader:1119:32)",
      "    at Module._load (node:internal/modules/cjs/loader:960:12)",
      "    at Module.require (node:internal/modules/cjs/loader:1143:19)"
    ]
  }
}

Is someone have the same issue? a workaround?
Thanks

Hmm, our Vercel deployments on v6.1 are looking good (also using dbAuth). I’m surprised the generateGraphiQLHeader module is being imported in production. This is normally turned off in production.

Did you add any dependencies to your project? Or set an env vars for Node in your Vercel build?

If your repo is public, sharing the link would be helpful as well.

Any thoughts here @dthyresson?

Next debugging thoughts:

  • did you add DB and SESSION_SECRET env vars to Vercel?
  • did you set the directives on your SDL queries and mutations, e.g. @requireAuth If you’re trying to hit an endpoint where auth is required, you’ll see an error if you’re not logged in.

Neither of the above explain why you’d see a “missing import” error, however.

Are you setting the generateGraphiQLHeader in your code? in development perhaps?

Did you generate it? If so, I suggest removing.

We’re going to remove generateGraphiQLHeader in favor of the redwoodJS Dev Studio.

Studio can to dbAuth impersonation currently and is the preferred method.

See: Redwood Studio [Experimental]

Thanks for your quick answer @thedavid!
So no, my repo is private… however i can add you to repo collaborators if you give me your github name.

I omitted…

  • yes i add DB and SECRET env vars to Vercel
  • yes i my directives on SDL seems to bee good, and anyway in my local app it works
  • and yes that does not explain the “missing import”, this the thing

Thank for your answer too @dthyresson!

So actually i have no idea…
I can imagine the file was generated by RW, maybe during the setup or maybe during some cli commands.

Do you really think i can delete the file and remove the corresponding import line in the graphql.ts file and the line in the createGraphQLHandler?
Can it be enough or should i try the experimental studio in addition?

Also, i omitted to mention that i recently upgrade RW from 6.0.3 to 6.1.0, mayby that can help to understand…

Yes, you can remove both.

Here is my handler for an app I deployed to Netlify this morning:

import { createGraphQLHandler } from '@redwoodjs/graphql-server'

import directives from 'src/directives/**/*.{js,ts}'
import sdls from 'src/graphql/**/*.sdl.{js,ts}'
import services from 'src/services/**/*.{js,ts}'

import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,
  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect()
  },
})

Netlify used to have the same error you mentioned; just remove it for now and if you do need to have GraphiQL auth, then Studio is a better option now.

We’ll actually be removing the headers option once Studio comes out of experimental preview: redwood/packages/graphql-server/src/createGraphQLYoga.ts at 220a7539573aba331735a207e0497abeb5cfa3e8 · redwoodjs/redwood · GitHub

Hi @dthyresson,

Thanks for the solution.
I’m not sure to well understanding…

Ok, i have to remove createGraphQLHandler.
But after that, knowing that i need graphiql auth, according to you, should it works with actual studio or should i configure the experimental one to make it work?

Because i tried with the experimental but that not works, and the issue is on local too…
When i yarn rw dev, the 5 first lines are in error:

web |   ➜  Local:   http://localhost:8910/
web | 5:08:41 PM [vite] http proxy error at /auth?method=getToken:
web | ⌛ API Server launching, please refresh your page...
web | 5:08:41 PM [vite] http proxy error at /graphql:
web | Error: connect ECONNREFUSED ::1:8911
web |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
gen | Generating full TypeScript definitions and GraphQL schemas
gen | Done.
api | Building... Took 1090 ms
api | Setting up OpenTelemetry using the setup file: /Users/vincent/Sites/myapp/api/src/opentelemetry.ts
api | Debugger listening on ws://127.0.0.1:18911/0d39bb14-e91b-4b37-8539-201db6e5d1f8
api | For help, see: https://nodejs.org/en/docs/inspector
api | Starting API Server...
api | Loading server config from /Users/vincent/Sites/myapp/api/server.config.js
api |
api | Importing Server Functions...
api | 17:08:49 🌲 Subscriptions are disabled.
api | /graphql 1838 ms
api | /auth 3 ms
api | ...Done importing in 1842 ms
api | Took 1895 ms
api | API listening on http://localhost:8911/
api | GraphQL endpoint at /graphql
api | 17:08:49 🌲 Server listening at http://[::]:8911
api | 17:08:49 🐛 GraphiQL and Introspection Config
api | 🗒 Custom
api | {
api |   "defaultAllowedOperations": [
api |     "query",
api |     "mutation"
api |   ],
api |   "defaultError": "Something went wrong.",
api |   "disableIntrospection": false,
api |   "disableGraphQL": false,
api |   "graphiql": {
api |     "title": "Redwood GraphQL Playground",
api |     "headers": "{\"x-auth-comment\": \"See documentation: https://redwoodjs.com/docs/cli-commands#setup-graphiql-headers on how to auto generate auth headers\"}",
api |     "defaultQuery": "query Redwood {\n    redwood {\n    version\n    }\n  }",
api |     "headerEditorEnabled": true
api |   },
api |   "graphiQLEndpoint": "/graphql"
api | }

So i can open my app, but the logs in the terminal said something wrong with gql auth i can imagine…

...
api | {"stack":"Error: connect ECONNREFUSED 127.0.0.1:4318\n    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)\n    at __node_internal_exceptionWithHostPort (node:internal/errors:668:12)\n    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)\n    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)","message":"connect ECONNREFUSED 127.0.0.1:4318","errno":"-61","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":"4318","name":"Error"}
api | {"stack":"Error: connect ECONNREFUSED 127.0.0.1:4318\n    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)\n    at __node_internal_exceptionWithHostPort (node:internal/errors:668:12)\n    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)\n    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17)","message":"connect ECONNREFUSED 127.0.0.1:4318","errno":"-61","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":"4318","name":"Error"}
...

Do you have an idea about this?
Thanks in advance

Hi @thedavid @dthyresson,

I’m sorry i had a little abandoned the deployment so far and I had refitted to the dev.
So today i would like to make the deploy work.

@thedavid to make the help easy, i switch my repo to public visibility.

And the deployed url : https://coluck.vercel.app/

@dthyresson for now i kept the basic configuration without RedwoodJS Dev Studio, because when i tried, i got the error mentioned in my previous message.

So for now :

  • I can signup in my app, but i cannot signin (FUNCTION_INVOCATION_FAILED)
  • I created a demo user for you to test : demo@demo.com (pass : demo)
  • It seems to be the getCurrentUser that crash, but i can find why for now…
  • Maybe helpful : https://coluck.vercel.app/api/graphql

Please, can you help me to make work?

Thank you a lot in advance.

@dthyresson @thedavid actually it’s ok my site is alive !!!
I re-test to simply remove generateGraphiQLHeaders, and it works !
Thanks

2 Likes