|
2 | 2 |
|
3 | 3 | This is the sample project that belongs to the [React & Apollo Tutorial](https://www.howtographql.com/react-apollo/0-introduction/) on How to GraphQL. |
4 | 4 |
|
5 | | -## Running the App |
| 5 | +## How to use |
6 | 6 |
|
7 | 7 | ### 1. Clone repository |
8 | 8 |
|
9 | 9 | ```sh |
10 | 10 | git clone https://github.com/howtographql/react-apollo/ |
11 | 11 | ``` |
12 | 12 |
|
13 | | -### 2. Deploy the Prisma database service |
| 13 | +### 2. Install dependencies & Deploy the Prisma database API |
14 | 14 |
|
15 | 15 | ```sh |
16 | 16 | cd react-apollo/server |
| 17 | +yarn install |
17 | 18 | yarn prisma deploy |
18 | 19 | ``` |
19 | 20 |
|
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: |
63 | 69 |
|
64 | 70 | ```sh |
65 | | -yarn install |
66 | 71 | yarn start |
67 | 72 | ``` |
68 | 73 |
|
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). |
70 | 75 |
|
71 | | -### 5. Run the app |
| 76 | +### 4. Run the app |
72 | 77 |
|
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): |
74 | 79 |
|
75 | 80 | ```sh |
76 | 81 | yarn install |
77 | 82 | yarn start |
78 | 83 | ``` |
79 | 84 |
|
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). |
0 commit comments