Nexus-plugin-prisma: Invalid `photon.()` invocation

Created on 28 Nov 2019  Β·  10Comments  Β·  Source: graphql-nexus/nexus-plugin-prisma

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.

Most helpful comment

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.

All 10 comments

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:

  • 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.
  • Prisma should check if the database is available on startup and output a warning if not. For example by using 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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

malekjaroslav picture malekjaroslav  Β·  5Comments

RAW4RMCS picture RAW4RMCS  Β·  3Comments

macrozone picture macrozone  Β·  3Comments

jamesopti picture jamesopti  Β·  4Comments

marticrespi picture marticrespi  Β·  4Comments