Node.js GraphQL API Stops working as soon as I deploy it: "Error validating datasource `db`: the URL must start with the protocol `mysql://"

2021-12-08T16:51:04

I build a GraphQL API with Apollo and Prisma ORM which is connected to my hosted MySQL Database (The Database has already content in it). When I run it on my localhost everything works fine and I can query the Database with GraphQL statements. As soon as I deploy my node.js project to DigitalOcean (auto deployed with GitHub) it stops working and I get the following error:

{
  "errors": [
    {
      "message": "\nInvalid `prisma.content.findMany()` invocation in\n/workspace/src/schema.js:36:29\n\n  33 const resolvers = {\n  34   Query: {\n  35     memes: (parent, args) => {\n→ 36       return prisma.content.findMany(\n  error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.\n  -->  schema.prisma:7\n   | \n 6 |   provider = \"mysql\"\n 7 |   url      = env(\"DATABASE_URL\")\n   | \n\nValidation Error Count: 1",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "memes"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "clientVersion": "3.6.0",
          "stacktrace": [
            "Error: ",
            "Invalid `prisma.content.findMany()` invocation in",
            "/workspace/src/schema.js:36:29",
            "",
            "  33 const resolvers = {",
            "  34   Query: {",
            "  35     memes: (parent, args) => {",
            "→ 36       return prisma.content.findMany(",
            "  error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.",
            "  -->  schema.prisma:7",
            "   | ",
            " 6 |   provider = \"mysql\"",
            " 7 |   url      = env(\"DATABASE_URL\")",
            "   | ",
            "",
            "Validation Error Count: 1",
            "    at cb (/workspace/node_modules/@prisma/client/runtime/index.js:38689:17)",
            "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
          ]
        }
      }
    }
  ],
  "data": null
}

Here is my schema.prisma file:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}
...

The only thing that is different from the hosted project compared to the local project is that I put .env file and node_modules on the .gitignore file. So it seems like the project is accessing the wrong DATABASE_URL, but how should the hosted project know the DATABASE_URL in my .env file when the .env file is on .gitignore?

Here is what I do:

  1. Change the DATABASE_URL in my .env file to my local MySQL Database hosted on a docker container
  2. Run npx prisma migrate dev --preview-feature to generate the migration files
  3. Run git add .
  4. Run git commit -m "New Commit"
  5. Run DATABASE_URL=mysql://censored:censored@censored:3306/censored npx prisma migrate resolve --applied "my_migration_folder_name" --preview-feature which succeeds and tells me "Migration my_migration_folder_name marked as applied."
  6. Run git push

I can see that the Migration is successfully created on my MySQL Database but as soon as I run the app and try to query the database it gives me that error.

The code has to be correct because it is working on my localhost even when querying the hosted MySQL Database. I also double checked that the Model in the schema.prisma file is in sync with my hosted MySQL Database schema.

I'm running out of ideas on what I could try.

EDIT

I actually think it has something to do with the environment variables I set in the settings of my DigitalOcean application. Before it was set to:

  envs:
  - key: DATABASE_URL
    scope: RUN_AND_BUILD_TIME
    value: ${db.DATABASE_URL}

Now I set it to:

  envs:
  - key: DATABASE_URL
    scope: RUN_AND_BUILD_TIME
    value: mysql://censored:cesnored@censored:3306/censored

I thought that this will fix the problem but now it tells me that the connection fails because of wrong database credentials even though it is the right link with the right credentials.

Copyright License:
Author:「HavanaSun」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/70272207/node-js-graphql-api-stops-working-as-soon-as-i-deploy-it-error-validating-data

About “Node.js GraphQL API Stops working as soon as I deploy it: "Error validating datasource `db`: the URL must start with the protocol `mysql://"” questions

I build a GraphQL API with Apollo and Prisma ORM which is connected to my hosted MySQL Database (The Database has already content in it). When I run it on my localhost everything works fine and I can
I setup two projects, Node.js and React in Nx monorepo. I would like to use GraphQL for communication. Projects I'm running with command nx serve api(Node.js) and nx serve totodile (React). Problem...
I see that a Node.js GraphQL API is very popular choice among mobile devs cause it is saving a lot of bandwidth and fetching only necessary data. So I also developed a GraphQL API with Apollo and I'm
I am working on the node.js and express to build API, however I want to make the API design on the runtime by designing the REST api endpoint with body param and return param, but how could I
I have been trying to deploy a backend api service made with graphql api and express to Amazon web services. This is my folder structure Graphql-api -src -index.js -serverl...
I have problems trying to deploy a graphql API to Azure web apps (I don't know if it's the right place but here's my case) My expectation I want to deploy a graphql API using a docker-compose file ...
I'm trying to deploy and run a POC WS on my server. The WS works fine on my dev computer.I package the app using the dist command. I upload and unzip everything on the server, then I start the server
I have a node.js API microservice that leverages graphql library. My API microservice connects with another node.js microservice that does a graphql mutation inside a MySql database. My api microse...
When I am running, the command npm run graphql-deploy in my local it stuck at lerna info Executing command in 1 package: "npm run graphql-deploy". Not moving forward. And if I run same co...
I am trying to deploy a GraphQL server on node.js platform using Azure functions. I have been able to deploy a basic hello world app. However, I need to get data from a backend API in the resolver....

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.