I have followed the instructions in the README.md file:
- Deploy the Prisma database service
yarn prisma deploy
When prompted where (i.e. to which cluster) you want to deploy your service, choose any of the public clusters, e.g. public-us1 or public-eu1. (If you have Docker installed, you can also deploy locally.)
Actually it does not prompt for any cluster, it returns:
myfolder\graphql-js> yarn prisma deploy
yarn run v1.6.0
$ prisma deploy
! Cluster undefined does not exist.
Get in touch if you need help: https://www.graph.cool/forum
To get more detailed output, run $ export DEBUG="*"
Done in 16.72s.
I have never used Prisma or GraphQL before, is there something I'm missing?
I'm at this step of the tutorial: https://www.howtographql.com/graphql-js/4-adding-a-database/
Everything worked out perfectly until now.
EDIT:
Running "prisma init" seems to be giving me the right output:
myfolder\graphql-js>prisma init
? Connect to your database, set up a new one or use hosted sandbox? (Use arrow keys
)
You can set up Prisma for local development (requires Docker)
> Use existing database Connect to existing database
Create new database Set up a local database using Docker
Or use a free hosted Prisma sandbox (includes database)
sandbox-eu1 Free development server on Prisma Cloud (incl. databas
e)
(Move up and down to reveal more choices)
I select "sandbox-eu1":
\graphql-js>prisma init
? Connect to your database, set up a new one or use hosted sandbox? sandbox-eu1
Free development server on Prisma Cloud (incl. database)
? How do you want to call your service? graphql-js
? To which stage do you want to deploy? dev
Created 2 new files:
prisma.yml Prisma service definition
datamodel.graphql GraphQL SDL-based datamodel (foundation for database)
You now can run $ prisma deploy to deploy your database service.
'docker-compose' is not recognized as an internal or external command,
operable program or batch file.
To install docker-compose, please follow this link: https://docs.docker.com/compose/install/
As suggested by the cmd output, I run "prisma deploy":
\graphql-js>prisma deploy
Creating stage dev for service graphql-js โ
Deploying service `graphql-js` to stage `dev` to server `prisma-eu1` 197ms
Changes:
User (Type)
+ Created type `User`
+ Created field `id` of type `GraphQLID!`
+ Created field `name` of type `String!`
+ Created field `updatedAt` of type `DateTime!`
+ Created field `createdAt` of type `DateTime!`
Applying changes 1.3s
Your Prisma GraphQL database endpoint is live:
HTTP: https://eu1.prisma.sh/myrandomstring/graphql-js/dev
WS: wss://eu1.prisma.sh/myrandomstring/graphql-js/dev
Now I can proceed to step 3 and 4:
- Set the Prisma service endpoint
From the output of the previous command, copy the HTTP endpoint and paste it into src/index.js where it's used to instantiate the Prisma binding. You need to replace the current placeholder PRISMA_ENDPOINT:
- Start the server & open Playground
To interact with the API in a GraphQL Playground, all you need to do is execute the dev script defined in package.json:
However if I now go to http://localhost:4000/ and try to run any query I get this:
{
"data": null,
"errors": [
{
"message": "Not authenticated",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"post"
]
}
]
}
Based on my understanding this is happening because I'm missing the authorization header, first I need to generate a token:
\graphql-js>prisma token
There is no secret set in the prisma.yml
Damn, there's no secret ๐ Ok, let's add it: (I will copy the same secret from src\index.js)
endpoint: https://eu1.prisma.sh/myrandomstring/graphql-js/dev
datamodel: datamodel.graphql
secret: "mysecret123"
Ok, now it seems to work:
\graphql-js>prisma token
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InNlcnZpY2UiOiJncmFwaHFsLWpzQGRldiIsInJvbGVzIjpbImFkbWluIl19LCJpYXQiOjE1MjQ2NjM2NDYsImV4cCI6MTUyNTI2ODQ0Nn0.sBx6zl-xv30Cw03UutMssjA7i272gXkuJUHmHNlaeBI
Let's add it to the HTTP headers in the GraphQL playground: (as shown in https://www.howtographql.com/graphql-js/4-adding-a-database/)
{
"Authentication": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InNlcnZpY2UiOiJncmFwaHFsLWpzQGRldiIsInJvbGVzIjpbImFkbWluIl19LCJpYXQiOjE1MjQ2NjM2NDYsImV4cCI6MTUyNTI2ODQ0Nn0.sBx6zl-xv30Cw03UutMssjA7i272gXkuJUHmHNlaeBI"
}
Restart everything up, go to localhost:4000, run a test query:
{
"data": null,
"errors": [
{
"message": "Not authenticated",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"post"
]
}
]
}
Still not working! ๐ฉ