Skip to content

Commit 9d02109

Browse files
committed
polish and update server to latest prisma version
1 parent ffb187f commit 9d02109

23 files changed

+1547
-1442
lines changed

server/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env*
2+
dist
3+
package-lock.json
4+
node_modules
5+
.idea
6+
.vscode
7+
*.log

server/.graphqlconfig.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
projects:
22
app:
3-
schemaPath: "src/schema.graphql"
3+
schemaPath: src/schema.graphql
44
extensions:
55
endpoints:
6-
default: "http://localhost:4000"
6+
default: http://localhost:4000
77
database:
8-
schemaPath: "src/generated/prisma.graphql"
8+
schemaPath: src/generated/prisma.graphql
99
extensions:
1010
prisma: database/prisma.yml

server/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# hackernews-graphql-js
2+
3+
This repository contains the final project for the [**GraphQL.js tutorial**](https://www.howtographql.com/graphql-js/0-introduction/) on [How to GraphQL](https://www.howtographql.com/). Note that it also serves as foundation for all frontend tutorials on the site.
4+
5+
## Usage
6+
7+
### 1. Clone repository & install dependencies
8+
9+
```sh
10+
git clone https://github.com/howtographql/graphql-js
11+
cd graphql-js
12+
yarn install # or `npm install`
13+
```
14+
15+
### 2. Deploy the Prisma database service
16+
17+
```sh
18+
yarn prisma deploy
19+
```
20+
21+
You need to setup a Prisma service. You can refer to [this Qucikstart](https://www.prisma.io/docs/quickstart/) to lear how.
22+
23+
### 3. Set the Prisma service endpoint
24+
25+
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__`:
26+
27+
```js
28+
const server = new GraphQLServer({
29+
typeDefs: './src/schema.graphql',
30+
resolvers,
31+
context: req => ({
32+
...req,
33+
db: new Prisma({
34+
typeDefs: 'src/generated/prisma.graphql',
35+
endpoint: "__PRISMA_ENDPOINT__",
36+
debug: true
37+
}),
38+
}),
39+
})
40+
```
41+
42+
For example:
43+
44+
```js
45+
const server = new GraphQLServer({
46+
typeDefs: './src/schema.graphql',
47+
resolvers,
48+
context: req => ({
49+
...req,
50+
db: new Prisma({
51+
typeDefs: 'src/generated/prisma.graphql',
52+
endpoint: "https://eu1.prisma.sh/public-hillcloak-flier-942261/hackernews-graphql-js/dev",
53+
debug: true,
54+
}),
55+
}),
56+
})
57+
```
58+
59+
Note that the part `public-hillcloak-flier-952361` of the URL is unique to _your_ service.
60+
61+
### 4. Start the server & open Playground
62+
63+
To interact with the API in a GraphQL Playground, all you need to do is execute the `dev` script defined in `package.json`:
64+
65+
```sh
66+
yarn dev
67+
```

server/database/datamodel.graphql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
type Vote {
2-
id: ID! @unique
3-
link: Link!
4-
user: User!
5-
}
6-
71
type Link {
82
id: ID! @unique
93
createdAt: DateTime!
@@ -21,3 +15,9 @@ type User {
2115
links: [Link!]!
2216
votes: [Vote!]!
2317
}
18+
19+
type Vote {
20+
id: ID! @unique
21+
link: Link!
22+
user: User!
23+
}

server/database/prisma.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
# the name for the service (will be part of the service's HTTP endpoint)
2-
service: hackernews-graphql-js
3-
4-
# the cluster and stage the service is deployed to
5-
stage: dev
6-
7-
# to disable authentication:
8-
# disableAuth: true
1+
endpoint: __PRISMA_ENDPOINT__
2+
datamodel: datamodel.graphql
93
secret: mysecret123
10-
11-
# the file path pointing to your data model
12-
datamodel: datamodel.graphql
4+
hooks:
5+
post-deploy:
6+
- yarn graphql get-schema --project database

server/package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
{
2-
"name": "hackernews-graphql-js",
2+
"name": "hackernews-node",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
36
"scripts": {
47
"start": "node src/index.js",
58
"dev": "npm-run-all --parallel start playground",
69
"playground": "graphql playground",
7-
"prisma": "prisma"
10+
"prisma": "prisma",
11+
"graphql": "graphql"
812
},
913
"dependencies": {
1014
"bcryptjs": "^2.4.3",
11-
"graphql-yoga": "1.4.3",
12-
"prisma-binding": "1.5.16"
15+
"graphql-yoga": "^1.7.0",
16+
"jsonwebtoken": "^8.2.0",
17+
"prisma-binding": "^2.0.2"
1318
},
1419
"devDependencies": {
15-
"graphql-cli": "2.15.8",
16-
"npm-run-all": "4.1.2",
17-
"prisma": "1.6.3"
20+
"graphql-cli": "^2.16.4",
21+
"npm-run-all": "^4.1.2",
22+
"prisma": "^1.9.0"
1823
}
1924
}

0 commit comments

Comments
 (0)