Skip to content

Commit e707b81

Browse files
committed
Deploy the GraphQL server
1 parent 99bac7d commit e707b81

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# GraphQL/REST API Demo
22

3-
A demo of what an equivalent REST API and GraphQL interface look like. This code is used in the first chapter of the forthcoming [The GraphQL Guide](https://graphql.guide/) by [John Resig](https://johnresig.com/) and [Loren Sands-Ramshaw](http://lorensr.me/).
3+
A demo of what an equivalent REST API and GraphQL API look like. This code is used in the first chapter of [The GraphQL Guide](https://graphql.guide/) by [John Resig](https://johnresig.com/) and [Loren Sands-Ramshaw](http://lorensr.me/). Here's the GraphQL server's GraphiQL:
4+
5+
[ch1.graphql.guide/graphql](https://ch1.graphql.guide/graphql)
46

57
## Installation
68

@@ -35,8 +37,8 @@ node rest-server.js
3537

3638
You can access the REST API by opening your browser and visiting either of the following URLs:
3739

38-
* [http://localhost:3000/users](http://localhost:3000/users) - All users.
39-
* [http://localhost:3000/users/123](http://localhost:3000/users/123) - An individual user record.
40+
* [localhost:3000/users](http://localhost:3000/users) - All users.
41+
* [localhost:3000/users/123](http://localhost:3000/users/123) - An individual user record.
4042

4143
## GraphQL Server
4244

@@ -50,6 +52,6 @@ node graphql-server.js
5052

5153
You can access the GraphQL data by opening your browser and visiting the [GraphiQL](https://github.com/graphql/graphiql) view at:
5254

53-
* [http://localhost:3000/graphql](http://localhost:3000/graphql)
55+
* [localhost:3000/graphql](http://localhost:3000/graphql)
5456

5557
You should see a console interface into which you can run GraphQL queries and see their results. You should also be able to browse the full schema and see all of the types that are available to you and what data they provide.

models.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
'use strict'
22
const mongoose = require('mongoose')
33

4+
const inDevelopment = process.env.NODE_ENV !== 'production'
5+
46
// Connect to the local MongoDB database named “testdb”
5-
mongoose.connect('mongodb://localhost/testdb')
7+
mongoose.connect(
8+
inDevelopment ? 'mongodb://localhost/testdb' : process.env.MONGO_URL
9+
)
610

711
// Create a Group schema to be stored in the MongoDB database
812
const GroupSchema = new mongoose.Schema({

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
"name": "graphql-rest-api-demo",
33
"version": "0.0.1",
4-
"description": "A demo of what an equivalent REST API and GraphQL interface look like.",
4+
"description":
5+
"A demo of what an equivalent REST API and GraphQL interface look like.",
56
"main": "graphql-server.js",
67
"scripts": {
78
"start": "node graphql-server.js",
89
"start-rest": "node rest-server.js",
9-
"prettify": "prettier --write *.js"
10+
"prettify": "prettier --write *.js",
11+
"deploy": "now -e NODE_ENV=production -e MONGO_URL=@ch1-mongo-url",
12+
"alias": "now alias"
13+
},
14+
"now": {
15+
"name": "guide-ch1",
16+
"alias": "ch1.graphql.guide"
1017
},
1118
"author": "John Resig <jeresig@gmail.com>",
1219
"license": "MIT",

0 commit comments

Comments
 (0)