TypeError: Only absolute URLs are supported
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
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:
- The Prisma CLI deploys the Prisma API (on a demo server or locally with Docker)
- After the successful deploy, the HTTP endpoint to access is printed to the console
- The endpoint is also written to
prisma.ymlas theendpointproperty - Because of the
post-deployhook inprisma.yml, the CLI invokes theprisma generatecommand (note that thepost-deployhook will not be required any more once this feature is implemented) - This triggers the (re-)generation of the Prisma client, which reads the freshly written
endpointfromprisma.ymland writes it into/src/generated/prisma-client/index.js.
Please reopen the issue if you're still running into trouble! 🙌
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"
]
}
]
}
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.
No, it's empty
let me try the rest
running prisma generate manually fixed it
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.
I'm not seeing any logs :/
What happens when you run prisma deploy?
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 ×
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 :)
ok, no probs. Thanks for your help :)
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.
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.
No I am not using dotenv. I was learning on HowToGraphql portal. Followed all the steps as specified in the documentation.
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
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"
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.
I'm facing the same issue, using Prisma 1.34
- 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/
-
I'm using dotenv.config() Then I import : generated/prisma-client
-
I'm logging the value of PRISMA_ENDPOINT, it shows the valid output in console
-
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();
-
But while hitting the API created, I get the same error - "Only absolute URLs are supported"
-
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?
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