Skip to content

Commit 9582e18

Browse files
author
Carlos Rufo
authored
Merge branch 'master' into develop
2 parents 8c14ed5 + 384f1ec commit 9582e18

File tree

9 files changed

+79
-75
lines changed

9 files changed

+79
-75
lines changed

README.md

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,84 @@
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

99
```sh
1010
git clone https://github.com/howtographql/react-apollo/
1111
```
1212

13-
### 2. Deploy the Prisma database service
13+
### 2. Install dependencies & Deploy the Prisma database API
1414

1515
```sh
1616
cd react-apollo/server
17+
yarn install
1718
yarn prisma deploy
1819
```
1920

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-
})
56-
```
57-
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:
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
67+
68+
To start the server, all you need to do is execute the `start` script by running the following command inside the `server` directory:
6369

6470
```sh
65-
yarn install
6671
yarn start
6772
```
6873

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`.
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).
7075

71-
### 5. Run the app
76+
### 4. Run the app
7277

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):
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):
7479

7580
```sh
7681
yarn install
7782
yarn start
7883
```
7984

80-
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/prisma/prisma.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Specifies the HTTP endpoint of your Prisma API.
2-
#endpoint: ''
3-
endpoint: https://eu1.prisma.sh/carlos-rufo-20c5e9/server/dev
2+
endpoint: ''
43

54
# Defines your models, each model is mapped to the database as a table.
65
datamodel: datamodel.prisma

src/components/App.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ import Search from './Search'
99
class App extends Component {
1010
render() {
1111
return (
12-
<div className='center w85'>
12+
<div className="center w85">
1313
<Header />
14-
<div className='ph3 pv1 background-gray'>
14+
<div className="ph3 pv1 background-gray">
1515
<Switch>
16-
<Route exact path='/' render={() => <Redirect to='/new/1' />} />
17-
<Route exact path='/create' component={CreateLink} />
18-
<Route exact path='/login' component={Login} />
19-
<Route exact path='/search' component={Search} />
20-
<Route exact path='/top' component={LinkList} />
21-
<Route exact path='/new/:page' component={LinkList} />
16+
<Route exact path="/" render={() => <Redirect to="/new/1" />} />
17+
<Route exact path="/create" component={CreateLink} />
18+
<Route exact path="/login" component={Login} />
19+
<Route exact path="/search" component={Search} />
20+
<Route exact path="/top" component={LinkList} />
21+
<Route exact path="/new/:page" component={LinkList} />
2222
</Switch>
2323
</div>
2424
</div>
2525
)
2626
}
2727
}
2828

29-
export default App
29+
export default App

src/components/CreateLink.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const POST_MUTATION = gql`
1818
class CreateLink extends Component {
1919
state = {
2020
description: '',
21-
url: ''
21+
url: '',
2222
}
2323

2424
render() {
@@ -51,13 +51,13 @@ class CreateLink extends Component {
5151
const orderBy = 'createdAt_DESC'
5252
const data = store.readQuery({
5353
query: FEED_QUERY,
54-
variables: { first, skip, orderBy }
54+
variables: { first, skip, orderBy },
5555
})
5656
data.feed.links.unshift(post)
5757
store.writeQuery({
5858
query: FEED_QUERY,
5959
data,
60-
variables: { first, skip, orderBy }
60+
variables: { first, skip, orderBy },
6161
})
6262
}}
6363
>
@@ -68,4 +68,4 @@ class CreateLink extends Component {
6868
}
6969
}
7070

71-
export default CreateLink
71+
export default CreateLink

src/components/Header.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ class Header extends Component {
4242
logout
4343
</div>
4444
) : (
45-
<Link to="/login" className="ml1 no-underline black">
46-
login
45+
<Link to="/login" className="ml1 no-underline black">
46+
login
4747
</Link>
48-
)}
48+
)}
4949
</div>
5050
</div>
5151
)

src/components/Link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const VOTE_MUTATION = gql`
2626
class Link extends Component {
2727
render() {
2828
const authToken = localStorage.getItem(AUTH_TOKEN)
29-
29+
3030
return (
3131
<div className="flex mt2 items-start">
3232
<div className="flex items-center">

src/components/LinkList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class LinkList extends Component {
102102
const newLink = subscriptionData.data.newLink
103103
const exists = prev.feed.links.find(({ id }) => id === newLink.id)
104104
if (exists) return prev
105+
105106
return Object.assign({}, prev, {
106107
feed: {
107108
links: [newLink, ...prev.feed.links],

src/components/Login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Login extends Component {
2424
login: true, // switch between Login and SignUp
2525
email: '',
2626
password: '',
27-
name: ''
27+
name: '',
2828
}
2929

3030
render() {
@@ -88,4 +88,4 @@ class Login extends Component {
8888
}
8989
}
9090

91-
export default Login
91+
export default Login

src/components/Search.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ const FEED_SEARCH_QUERY = gql`
2727
`
2828

2929
class Search extends Component {
30-
3130
state = {
3231
links: [],
33-
filter: ''
32+
filter: '',
3433
}
3534

3635
render() {
@@ -39,7 +38,7 @@ class Search extends Component {
3938
<div>
4039
Search
4140
<input
42-
type='text'
41+
type="text"
4342
onChange={e => this.setState({ filter: e.target.value })}
4443
/>
4544
<button onClick={() => this._executeSearch()}>OK</button>
@@ -62,4 +61,4 @@ class Search extends Component {
6261
}
6362
}
6463

65-
export default withApollo(Search)
64+
export default withApollo(Search)

0 commit comments

Comments
 (0)