Skip to content

Commit 384f1ec

Browse files
authored
Merge pull request #66 from howtographql/prisma-client
Migrate server to Prisma client
2 parents 7dc3f55 + 44b1b86 commit 384f1ec

File tree

21 files changed

+3565
-3228
lines changed

21 files changed

+3565
-3228
lines changed

README.md

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is the sample project that belongs to the [React & Apollo Tutorial](https://www.howtographql.com/react-apollo/0-introduction/) on How to GraphQL.
44

5-
## Running the App
5+
## How to use
66

77
### 1. Clone repository
88

@@ -18,61 +18,68 @@ yarn install
1818
yarn prisma deploy
1919
```
2020

21-
When prompted where (i.e. to which _Prisma server_) you want to deploy your service, choose the **Demo server** which can be used for free in Prisma Cloud. If you haven't done so already, you will be asked to register with Prisma Cloud (which you can do via GitHub). For the following prompts in the terminal you can select the suggested values by hitting **Enter**. (If you have Docker installed, you can also choose to deploy Prisma locally by _Creating a new database_.)
22-
23-
### 3. Set the Prisma API endpoint
24-
25-
The `prisma deploy` command wrote the endpoint property into `server/database/prisma.yml`. Copy it from there and paste it into `server/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-
secret: 'mysecret123',
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/john-doe/hackernews-graphql-js/dev',
53-
secret: 'mysecret123',
54-
}),
55-
}),
56-
})
57-
```
58-
59-
### 4. Start the server
21+
Then, follow these steps in the interactive CLI wizard:
22+
23+
1. Select **Demo server**
24+
1. **Authenticate** with Prisma Cloud in your browser (if necessary)
25+
1. Back in your terminal, **confirm all suggested values**
26+
27+
<details>
28+
<summary>Alternative: Run Prisma locally via Docker</summary>
29+
30+
1. Ensure you have Docker installed on your machine. If not, you can get it from [here](https://store.docker.com/search?offering=community&type=edition).
31+
1. Create `docker-compose.yml` for MySQL (see [here](https://www.prisma.io/docs/prisma-server/database-connector-POSTGRES-jgfr/) for Postgres):
32+
```yml
33+
version: '3'
34+
services:
35+
prisma:
36+
image: prismagraphql/prisma:1.23
37+
restart: always
38+
ports:
39+
- "4466:4466"
40+
environment:
41+
PRISMA_CONFIG: |
42+
port: 4466
43+
databases:
44+
default:
45+
connector: mysql
46+
host: mysql
47+
port: 3306
48+
user: root
49+
password: prisma
50+
migrations: true
51+
mysql:
52+
image: mysql:5.7
53+
restart: always
54+
environment:
55+
MYSQL_ROOT_PASSWORD: prisma
56+
volumes:
57+
- mysql:/var/lib/mysql
58+
volumes:
59+
mysql:
60+
```
61+
1. Run `docker-compose up -d`
62+
1. Run `prisma deploy`
63+
64+
</details>
65+
66+
### 3. Start the server
6067

6168
To start the server, all you need to do is execute the `start` script by running the following command inside the `server` directory:
6269

6370
```sh
6471
yarn start
6572
```
6673

67-
> **Note**: If you want to interact with the GraphQL APIs inside a [GraphQL Playground](https://github.com/graphcool/graphql-playground), you can also run `yarn dev`.
74+
> **Note**: If you want to interact with the GraphQL API of the server inside a [GraphQL Playground](https://github.com/prisma/graphql-playground), you can navigate to [http://localhost:4000](http://localhost:4000).
6875

69-
### 5. Run the app
76+
### 4. Run the app
7077

71-
Now that the server is running, you can start the app as well. The commands need to be run in a new terminal tab/window inside the root directory `react-apollo` (because the current tab is blocked by the process running the server):
78+
Now that the server is running, you can start the React app as well. The commands need to be run in a new terminal tab/window inside the root directory `react-apollo` (because the current tab is blocked by the process running the server):
7279

7380
```sh
7481
yarn install
7582
yarn start
7683
```
7784

78-
You can now open your browser and use the app on `http://localhost:3000`.
85+
You can now open your browser and use the app on [http://localhost:3000](http://localhost:3000).

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: 0 additions & 10 deletions
This file was deleted.

server/database/prisma.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

server/package.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
{
22
"name": "hackernews-node",
33
"version": "1.0.0",
4-
"main": "index.js",
54
"license": "MIT",
65
"scripts": {
76
"start": "node src/index.js",
8-
"dev": "npm-run-all --parallel start playground",
9-
"playground": "graphql playground",
10-
"prisma": "prisma",
11-
"graphql": "graphql"
7+
"prisma": "prisma"
128
},
139
"dependencies": {
1410
"bcryptjs": "^2.4.3",
15-
"graphql-yoga": "^1.14.12",
16-
"jsonwebtoken": "^8.3.0",
17-
"prisma-binding": "^2.1.1"
11+
"graphql-yoga": "^1.7.0",
12+
"jsonwebtoken": "^8.2.0",
13+
"prisma-client-lib": "^1.22.2"
1814
},
1915
"devDependencies": {
20-
"graphql-cli": "^2.16.4",
21-
"npm-run-all": "^4.1.2",
22-
"prisma": "^1.12.0"
16+
"prisma": "^1.23.0"
2317
}
24-
}
18+
}
File renamed without changes.

server/prisma/prisma.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Specifies the HTTP endpoint of your Prisma API.
2+
endpoint: ''
3+
4+
# Defines your models, each model is mapped to the database as a table.
5+
datamodel: datamodel.prisma
6+
7+
# Specifies the language and directory for the generated Prisma client.
8+
generate:
9+
- generator: javascript-client
10+
output: ../src/generated/prisma-client
11+
12+
# Ensures Prisma client is re-generated after a datamodel change.
13+
hooks:
14+
post-deploy:
15+
- prisma generate

0 commit comments

Comments
 (0)