Skip to content

Commit d8c4af8

Browse files
authored
Merge branch 'master' into master
2 parents f25d841 + baa5aa5 commit d8c4af8

36 files changed

+5865
-828
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# dependencies
44
node_modules
5-
.graphcoolrd
5+
.graphcoolrc
66

77
# testing
88
/coverage

README.md

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,73 @@ This is the sample project that belongs to the [React & Apollo Tutorial](https:/
88

99
```sh
1010
git clone https://github.com/howtographql/react-apollo/
11-
cd react-apollo
1211
```
1312

14-
### 2. Create GraphQL API with [`graphcool`](https://www.npmjs.com/package/graphcool)
15-
16-
If you haven't already, install the Graphcool CLI:
13+
### 2. Deploy the Prisma database service
1714

1815
```sh
19-
# Install Graphcool CLI
20-
npm install -g graphcool
16+
cd react-apollo/server
17+
yarn prisma deploy
18+
```
19+
20+
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.)
21+
22+
### 3. Set the Prisma service endpoint
23+
24+
From the output of the previous command, copy the `HTTP` endpoint 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`:
25+
26+
```js
27+
const server = new GraphQLServer({
28+
typeDefs: './src/schema.graphql',
29+
resolvers,
30+
context: req => ({
31+
...req,
32+
db: new Prisma({
33+
typeDefs: 'src/generated/prisma.graphql',
34+
endpoint: '__PRISMA_ENDPOINT__',
35+
secret: 'mysecret123',
36+
}),
37+
}),
38+
})
39+
```
40+
41+
For example:
42+
43+
```js
44+
const server = new GraphQLServer({
45+
typeDefs: './src/schema.graphql',
46+
resolvers,
47+
context: req => ({
48+
...req,
49+
db: new Prisma({
50+
typeDefs: 'src/generated/prisma.graphql',
51+
endpoint: 'https://eu1.prisma.sh/public-hillcloak-flier-942261/hackernews-graphql-js/dev',
52+
secret: 'mysecret123',
53+
}),
54+
}),
55+
})
2156
```
2257

23-
Once it's installed, you can deploy the Graphcool service based on the existing definition inside the [`server`](./server) directory:
58+
Note that the part `public-hillcloak-flier-952361` of the URL is unique to your service.
59+
60+
### 4. Start the server
61+
62+
To start the server, all you need to do is install the the dependencies execute the `start` script by running the following command inside the `server` directory:
2463

2564
```sh
26-
cd server
2765
yarn install
28-
graphcool deploy
66+
yarn start
2967
```
3068

31-
When prompted which cluster you want to deploy to, choose any of the **Shared Clusters** options (`shared-eu-west-1`, `shared-ap-northeast-1` or `shared-us-west-2`).
69+
> **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`.
3270
33-
### 3. Connect the app with your GraphQL API
71+
### 5. Run the app
3472

35-
Paste the service ID (which you find in the generated `.graphcoolrc` file inside the `server` directory or by running `graphcool info`) into `./src/index.js` replacing the current placeholder `__SERVICE_ID__`.
36-
37-
### 4. Install dependencies & run locally
73+
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):
3874

3975
```sh
40-
cd ..
4176
yarn install
42-
yarn start # open http://localhost:3000 in your browser
77+
yarn start
4378
```
4479

45-
80+
You can now open your browser and use the app on `http://localhost:3000`.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"apollo-client-preset": "^1.0.1",
7-
"apollo-link-ws": "^1.0.0",
8-
"graphql": "^0.11.7",
9-
"graphql-tag": "^2.5.0",
10-
"react": "^16.0.0",
11-
"react-apollo": "^2.0.0",
12-
"react-dom": "^16.0.0",
6+
"apollo-client": "^2.2.0",
7+
"apollo-client-preset": "^1.0.6",
8+
"apollo-link": "^1.0.7",
9+
"apollo-link-ws": "^1.0.4",
10+
"graphql": "^0.12.3",
11+
"graphql-tag": "^2.6.1",
12+
"react": "^16.2.0",
13+
"react-apollo": "^2.0.4",
14+
"react-dom": "^16.2.0",
1315
"react-router": "^4.2.0",
1416
"react-router-dom": "^4.2.2",
1517
"react-scripts": "1.0.17",
16-
"subscriptions-transport-ws": "^0.9.4"
18+
"subscriptions-transport-ws": "^0.9.5"
1719
},
1820
"scripts": {
1921
"start": "react-scripts start",

server/.graphqlconfig.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
projects:
2+
app:
3+
schemaPath: "src/schema.graphql"
4+
extensions:
5+
endpoints:
6+
default: "http://localhost:4000"
7+
database:
8+
schemaPath: "src/generated/prisma.graphql"
9+
extensions:
10+
prisma: database/prisma.yml

server/database/datamodel.graphql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
type Vote {
2+
id: ID! @unique
3+
link: Link!
4+
user: User!
5+
}
6+
7+
type Link {
8+
id: ID! @unique
9+
createdAt: DateTime!
10+
description: String!
11+
url: String!
12+
postedBy: User
13+
votes: [Vote!]!
14+
}
15+
16+
type User {
17+
id: ID! @unique
18+
name: String!
19+
email: String! @unique
20+
password: String!
21+
links: [Link!]!
22+
votes: [Vote!]!
23+
}

server/database/prisma.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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
9+
secret: mysecret123
10+
11+
# the file path pointing to your data model
12+
datamodel: datamodel.graphql
13+
14+
cluster: nikolas/prisma-eu1

server/graphcool.yml

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

server/package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
2-
"name": "server",
3-
"version": "1.0.0",
4-
"description": "My Graphcool Service",
2+
"name": "hackernews-graphql-js",
3+
"scripts": {
4+
"start": "node src/index.js",
5+
"dev": "npm-run-all --parallel start playground",
6+
"playground": "graphql playground",
7+
"prisma": "prisma"
8+
},
59
"dependencies": {
6-
"@types/bcryptjs": "^2.4.1",
7-
"@types/validator": "^6.3.0",
810
"bcryptjs": "^2.4.3",
9-
"graphcool-lib": "^0.1.0",
10-
"graphql-request": "^1.4.0",
11-
"validator": "^9.0.0"
11+
"graphql-yoga": "1.3.2",
12+
"prisma-binding": "1.5.10"
13+
},
14+
"devDependencies": {
15+
"graphql-cli": "2.14.1",
16+
"npm-run-all": "4.1.2",
17+
"prisma": "1.2.2"
1218
}
13-
}
19+
}

server/src/email-password/authenticate.graphql

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

server/src/email-password/authenticate.ts

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

0 commit comments

Comments
 (0)