While trying to build an application backed by a serverless Apollo GraphQL instance, I encountered the following issue:
{
"errors": [
{
"message": "\nInvalid `photon.()` invocation in /var/task/src/node_modules/nexus-prisma/dist/builder.js:129:97\n\n\n\nundefined target=\"exit\" timestamp=\"2019-11-28T02:18:36.253Z\" fields={\"message\":\"127\"}",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"quizzes"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: ",
"Invalid `photon.()` invocation in /var/task/src/node_modules/nexus-prisma/dist/builder.js:129:97",
"",
"",
"",
"undefined target=\"exit\" timestamp=\"2019-11-28T02:18:36.253Z\" fields={\"message\":\"127\"}",
" at PhotonFetcher.<anonymous> (/var/task/src/node_modules/@prisma/photon/index.js:54:27)",
" at Generator.throw (<anonymous>)",
" at rejected (/var/task/src/node_modules/@prisma/photon/index.js:6:65)",
" at <anonymous>"
]
}
}
}
],
"data": null
}
I executed the following query from here to get the aforementioned result:
{
quizzes {
id
}
}
The source code of the entire application is available from https://github.com/kripod/exigo, along with the corresponding build log here.
I'm getting the same error.
Error:
Invalid `photon.()` invocation in /path/to/project/packages/server/node_modules/nexus-prisma/src/builder.ts:238:18
234 const photon = this.getPhoton(ctx)
235 assertPhotonInContext(photon)
236 return photon[mappedField.photonAccessor][
237 mappedField.operation
β 238 ](args
undefined target="exit" timestamp="2019-12-04T16:44:27.839Z" fields={"message":"1"}
at PhotonFetcher.<anonymous> (/path/to/project/node_modules/@prisma/photon/index.js:54:27)
at Generator.throw (<anonymous>)
at rejected (/path/to/project/node_modules/@prisma/photon/index.js:6:65)
Maybe good to know for you: I'm working with lerna to manage a multi-workspace project.
The project structure is as follows. I hope I've included every important file:
. βββ node_modules β βββ @prisma β β βββ engine-core β β βββ fetch-engine β β βββ generator-helper β β βββ get-platform β β βββ photon β β βββ sdk β βββ nexus β βββ nexus-prisma β βββ ... βββ lerna.json βββ package.json βββ packages β βββ app β β βββ node_modules β β βββ package.json β β βββ src β β β βββ... β β βββ tsconfig.json β β βββ tsconfig.paths.json β βββ common β β βββ node_modules β β βββ package.json β β βββ src β β β βββ... β β βββ tsconfig.json β β βββ tslint.json β βββ server β βββ node_modules β β βββ @types β β β βββ nexus-typegen β β βββ seed.ts β βββ package.json β βββ prisma β β βββ migrations β β β βββ 20191128230530 β β β β βββ README.md β β β β βββ schema.prisma β β β β βββ steps.json β β β βββ 20191204173112-init β β β β βββ README.md β β β β βββ schema.prisma β β β β βββ steps.json β β β βββ lift.lock β β βββ schema.prisma β β βββ seed.ts β βββ README.md β βββ src β β βββ context.ts β β βββ generated β β β βββ schema.graphql β β βββ schema β β β βββ Advertisement.ts β β β βββ index.ts β β β βββ JobLocation.ts β β β βββ Mutation.ts β β β βββ Query.ts β β βββ server.ts β βββ tsconfig.json βββ yarn.lock
relevant dependencies from packages/server/package.json:
"dependencies": {
"@prisma/photon": "2.0.0-preview017.2",
"graphql": "14.5.8",
"graphql-yoga": "1.18.3",
"nexus": "0.12.0-rc.5",
"nexus-prisma": "0.6.1"
},
"devDependencies": {
"@prisma/sdk": "^0.0.76",
"@types/node": "12.12.14",
"@types/ws": "6.0.4",
"prisma2": "2.0.0-preview017.2",
"ts-node": "8.5.3",
"ts-node-dev": "1.0.0-pre.44",
"typescript": "3.7.2"
},
@RafaelKr Thank you for the information. My project is also a multi-workspace one, and I just tarted to wonder whether that may be the root causeβ¦
I just copied my packages/server files to a standalone folder and getting the same error. So probably it's not the cause.
I'm using an environment variable for my database url in the schema.prisma file.
datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
}
By starting the server with DEBUG=* yarn start I could easily track down what caused the error for me:
engine stderr error: Environment variable not found: POSTGRES_URL.
--> schema.prisma:7
|
6 | provider = "postgresql"
7 | url = env("POSTGRES_URL")
8 | }
|
+15ms
Error:
Invalid `photon.()` invocation in /path/to/project/node_modules/nexus-prisma/src/builder.ts:238:18
234 const photon = this.getPhoton(ctx)
235 assertPhotonInContext(photon)
236 return photon[mappedField.photonAccessor][
237 mappedField.operation
β 238 ](args
undefined target="exit" timestamp="2019-12-04T19:34:15.893Z" fields={"message":"1"}
at PhotonFetcher.<anonymous> (/path/to/project/node_modules/@prisma/photon/index.js:54:27)
at Generator.throw (<anonymous>)
at rejected (/path/to/project/node_modules/@prisma/photon/index.js:6:65)
I just forgot to set the POSTGRES_URL environment variable for the dev script π€¦π»ββοΈ
I simply had to update my package.json script and now it's working perfectly! (I'm using the dotenv node plugin and have a .env file at the same level as my packages/server/package.json)
- "dev": "ts-node-dev --no-notify --respawn --transpileOnly src/server",
+ "dev": "ts-node-dev -r dotenv/config --no-notify --respawn --transpileOnly src/server",
But Prisma should definitely output at least a warning that this env var is not set.
But Prisma should definitely output at least a warning that this env var is not set.
π―
@RafaelKr Thank you for the thorough investigation! Iβm currently using SQLite for its simplicity, but it may cause trouble on AWS Lambda because of the read-only file systemβ¦
I just thought this further and came to the conclusion that Prisma always outputs that error when it can't reach the database. To check that, I shut down my Postgres Docker container and my assumption was confirmed.
So I would recommend the following things:
Invalid `photon.()` invocation in ... is not helpful. The root cause is an unsuccessful database connection/query, so this is the real error that should be logged.SELECT 1.The error Invalid
photon.()invocation in ... is not helpful. The root cause is an unsuccessful database connection/query, so this is the real error that should be logged.
nexus-prisma lib (this repo) should be able to help with βοΈ . It might be the most actionable thing for this issue in this repo.
I have the same error with different cause, what I did is to run photon in a plain play.js then node play.js. Then I found the error is about I have different formats of datetime that have been saved from other source other than photon.
Otherwise, the error message from the response is unreadable and been truncated.
Now that we have Nexus, this point is obsolete https://github.com/graphql-nexus/nexus-schema-plugin-prisma/issues/546#issuecomment-561847100. Also 6 months of work on Prisma Client has taken place. Going to close this issue. Please open new ones if new issues are encountered. ty!
Most helpful comment
I'm using an environment variable for my database url in the schema.prisma file.
By starting the server with
DEBUG=* yarn startI could easily track down what caused the error for me:I just forgot to set the
POSTGRES_URLenvironment variable for thedevscript π€¦π»ββοΈI simply had to update my package.json script and now it's working perfectly! (I'm using the
dotenvnode plugin and have a.envfile at the same level as my packages/server/package.json)But Prisma should definitely output at least a warning that this env var is not set.