prisma-examples icon indicating copy to clipboard operation
prisma-examples copied to clipboard

TypeError: Only absolute URLs are supported

Open jimjamdev opened this issue 8 years ago • 20 comments

Using the node-auth example on Ubuntu 18.04. When I start the project and try to query on my localhost playground, I get

Server is running on http://localhost:4000
TypeError: Only absolute URLs are supported

This is just a straight install from the example

jimjamdev avatar Nov 28 '18 23:11 jimjamdev

Thanks for opening this issue @jimmyjamieson, did you execute all instructions that were explained in the README successfully?

Also, when did that error happen eexactly? Was is after you sent a query or immediately after you had started the server with yarn start?

I believe the error happens because the generated Prisma client (in /src/generated/prisma-client/index.js) does not have its endpoint set. This should be fixed if you prisma deploy. When running prisma deploy, here's what's supposed to happen:

  1. The Prisma CLI deploys the Prisma API (on a demo server or locally with Docker)
  2. After the successful deploy, the HTTP endpoint to access is printed to the console
  3. The endpoint is also written to prisma.yml as the endpoint property
  4. Because of the post-deploy hook in prisma.yml, the CLI invokes the prisma generate command (note that the post-deploy hook will not be required any more once this feature is implemented)
  5. This triggers the (re-)generation of the Prisma client, which reads the freshly written endpoint from prisma.yml and writes it into /src/generated/prisma-client/index.js.

Please reopen the issue if you're still running into trouble! 🙌

nikolasburk avatar Nov 29 '18 09:11 nikolasburk

So, I've reset up, and went through the steps again to the same issue

Used the example here https://github.com/prisma/prisma-examples/tree/master/node/graphql-auth

npm i && prisma deploy and chose the demo service i created on prisma cloud, using the login steps, so it generates everything for me

run npm start and open localhost:4000

Do a test query in the Playground

# Write your query or mutation here
query {
  feed {
    id
    title
    author {
      name
    }
  }
}

and get the result

{
  "data": null,
  "errors": [
    {
      "message": "Only absolute URLs are supported",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "feed"
      ]
    }
  ]
}

jimjamdev avatar Nov 29 '18 17:11 jimjamdev

Hmm weird, can you please check in the generated /src/generated/prisma-client/index.js whether the endpoint is set (should be in line 19).

Also, can you confirm that prisma generate has been invoked successfully after the deploy? Could you please post the logs that you're seeing after running prisma deploy.

Finally, can you please try to run prisma generate manually and see if the issue still persists? Before running prisma generate, please ensure that the deploy was successful and that the endpoint in prisma.yml was set.

nikolasburk avatar Nov 29 '18 17:11 nikolasburk

No, it's empty

jimjamdev avatar Nov 29 '18 18:11 jimjamdev

let me try the rest

jimjamdev avatar Nov 29 '18 18:11 jimjamdev

running prisma generate manually fixed it

jimjamdev avatar Nov 29 '18 18:11 jimjamdev

Hmm, can you please run prisma deploy and paste the logs here. It seems like the post-deploy hook from prisma.yml is not being invoked for some reason.

nikolasburk avatar Nov 29 '18 18:11 nikolasburk

I'm not seeing any logs :/

jimjamdev avatar Nov 29 '18 18:11 jimjamdev

What happens when you run prisma deploy?

nikolasburk avatar Nov 29 '18 18:11 nikolasburk

Deploying service `rentipo-dev` to stage `dev` to server `prisma-eu1` 239ms
Service is already up to date.

post-deploy:
spawnSync prisma ENOENT
Running prisma generate ×

jimjamdev avatar Nov 29 '18 18:11 jimjamdev

I see, this looks like a bug in the Prisma CLI. Can you please open an issue in the main Prisma repo with that same output and the version of the Prisma CLI you're using :)

nikolasburk avatar Nov 29 '18 18:11 nikolasburk

ok, no probs. Thanks for your help :)

jimjamdev avatar Nov 29 '18 18:11 jimjamdev

Hi, I'm facing the same problem. When I run prisma deploy, there are no logs generating terminal is showing just ---- yarn run v1.15.2 $ prisma deploy Done in 0.13s. Also tried to run prisma generate. After completion of process it just returned ---- yarn run v1.15.2 $ prisma generate Done in 0.07s.

Also there is no endpoint specified at server/prisma/prisma.yml after running prisma deploy.

OmkarMS avatar Mar 28 '19 04:03 OmkarMS

Wild guess but are you using dotenv to set those environment variables? I was having the same problem and removing the ${env:PRISMA_ENDPOINT} variable that I had in the prisma.yml file solved my issue.

vincentvella avatar Mar 28 '19 04:03 vincentvella

No I am not using dotenv. I was learning on HowToGraphql portal. Followed all the steps as specified in the documentation.

OmkarMS avatar Mar 28 '19 06:03 OmkarMS

I encountered the same "absolute URL" error when following the How To GraphQL tutorial and, like @jimmyjamieson, inspection of src/generated/index.js showed that the endpoint was not getting set. After digging deeper I found that I had used an invalid service/staging name when initializing the Prisma client. the solution:

-navigate to server/prisma/prisma.yml and locate the invalid endpoint name:

# Specifies the HTTP endpoint of your Prisma API. #endpoint: '' endpoint: https://yourDemoServer/yourProjectID/helloWorld/helloWorld stage

-and change to a valid name:

# Specifies the HTTP endpoint of your Prisma API. #endpoint: '' endpoint: https://yourDemoServer/yourProjectID/hello-world/stage

-save the changes to your prisma.yml file -from command line navigate back to the server directory and do: yarn prisma deploy -you can then verify the endpoint gets set in the src/generated/prisma-client/index.js file -run yarn start to restart the server then in your browser navigate back to localhost:4000 to continue to with tutorial

wtait avatar Aug 12 '19 15:08 wtait

TL;DR Solution at the bottom

I have come across this problem while trying to set up multiple deployment environments for prisma (dev, staging and production).

### The problem

I used multiple env files to configure my prisma.yml file for deployment, my prisma.yml file looks something like this:

endpoint: ${env:PRISMA_ENDPOINT}
datamodel: ${env:PRISMA_DATAMODEL}

generate:
  - generator: javascript-client
    output: ${env:PRISMA_JS_OUTPUT_PATH}

And thus, my generated prisma-client/index.js file had the endpoint as:

endpoint: `${process.env["PRISMA_ENDPOINT"]}`

The prisma client was fetching the environment variable PRISMA_ENDPOINT from the environment variables defined in the root folder rather than the environment variables defined in the prisma project folder.

### The solution

The solution was very basic and works after every deploy and prisma-client generation.

Add the prisma endpoint environment variable to your root .env file(s). Like so:

PRISMA_ENDPOINT = "https://my-example-prisma-server.com/service/default"

the-dream-machine avatar Sep 04 '19 20:09 the-dream-machine

I would just like to add to this just in case someone else comes along with my same problem. I had require('dotenv').config() in my file along with const { prisma } = require('./generated/prisma') but I had them in the wrong order. You have to put the dotenv config BEFORE the prisma declaration.

gabrielruss avatar Sep 22 '19 20:09 gabrielruss

I'm facing the same issue, using Prisma 1.34

  1. I have .env file - PRISMA_ENDPOINT=http://localhost:4467

prisma.yml ->

endpoint: ${env:PRISMA_ENDPOINT}
datamodel: datamodel.graphql

generate:
  - generator: javascript-client
    output: ./src/generated/prisma-client/
  1. I'm using dotenv.config() Then I import : generated/prisma-client

  2. I'm logging the value of PRISMA_ENDPOINT, it shows the valid output in console

  3. After prisma generate -> generated/prisma-client/index.js has the following code snippet at the bottom -->

exports.Prisma = prisma_lib_1.makePrismaClientClass({
  typeDefs,
  models,
  endpoint: `${process.env["PRISMA_ENDPOINT"]}`
});
exports.prisma = new exports.Prisma();
  1. But while hitting the API created, I get the same error - "Only absolute URLs are supported"

  2. Putting the hardcoded url works but what's the point if it's not parsing the env vars

Is there anyone who found the solution?

pratikmakune3 avatar Mar 23 '21 07:03 pratikmakune3

This repository is about Prisma 2 related examples @pratikmakune3. If I understood your message correctly you are referring to Prisma 1. You should use https://github.com/prisma/prisma1-examples or https://github.com/prisma/prisma1

janpio avatar Mar 23 '21 17:03 janpio