Skip to content

Commit 22f2dbc

Browse files
committed
Use express-graphql GraphiQL feature
This changes Swapi-graphql to have just one root endpoint which serves graphql rather than two endpoints which serve graphql and graphiql respectively.
1 parent c239824 commit 22f2dbc

File tree

5 files changed

+25
-118
lines changed

5 files changed

+25
-118
lines changed

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
SWAPI GraphQL Wrapper
22
=====================
33

4-
A wrapper around [SWAPI](http://swapi.co) built using [graphql-js](https://github.com/graphql/graphql-js), with
5-
[GraphiQL](https://github.com/graphql/graphiql) included for easy exploration.
4+
A wrapper around [SWAPI](http://swapi.co) built using GraphQL.
65

7-
Try it out at http://graphql-swapi.parseapp.com/graphiql/.
6+
Uses:
7+
8+
* [graphql-js](https://github.com/graphql/graphql-js) - a JavaScript GraphQL runtime.
9+
* [DataLoader](https://github.com/facebook/dataloader) - for coalescing and caching fetches.
10+
* [express-graphql](https://github.com/graphql/express-graphql) - to provide HTTP access to GraphQL.
11+
* [GraphiQL](https://github.com/graphql/graphiql) - for easy exploration of this GraphQL server.
12+
13+
Try it out at http://graphql-swapi.parseapp.com/.
814

915
## Getting Started
1016

@@ -30,7 +36,7 @@ A local express server is in `./server`. It can be run with:
3036
npm start
3137
```
3238

33-
A GraphiQL instance will be opened at http://localhost:8080/graphiql to
39+
A GraphiQL instance will be opened at http://localhost:8080/ to
3440
explore the API.
3541

3642
## Parse Server
@@ -42,4 +48,4 @@ file, it can be deployed with:
4248
npm run deploy
4349
```
4450

45-
A sample deploy is at http://graphql-swapi.parseapp.com/graphiql/
51+
A sample deploy is at http://graphql-swapi.parseapp.com/

package.json

+4-10
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,20 @@
5555

5656
"start": "node server/lib/server.js",
5757
"prestart": "npm run build-server",
58-
"build-server": "npm run build-swapi && npm run build-server-js && npm run build-server-css && npm run build-server-html && npm run build-server-server",
59-
"build-server-js": "mkdir -p server/lib/graphiql/ && cp node_modules/graphiql/graphiql.min.js server/lib/graphiql/graphiql.min.js",
60-
"build-server-css": "mkdir -p server/lib/graphiql/ && cp node_modules/graphiql/graphiql.css server/lib/graphiql/graphiql.css",
61-
"build-server-html": "mkdir -p server/lib/graphiql/ && cp server/src/graphiql/index.html server/lib/graphiql/index.html",
62-
"build-server-server": "mkdir -p server/lib && babel server/src/server.js --optional runtime -o server/lib/server.js",
58+
"build-server": "npm run build-swapi && mkdir -p server/lib && babel server/src/server.js --optional runtime -o server/lib/server.js",
6359

6460
"predeploy": "npm run build-parse",
6561
"deploy": "cd parse/lib && parse deploy",
66-
"build-parse": "npm run build-swapi && npm run build-parse-cloud && npm run build-parse-public && npm run build-parse-config",
62+
"build-parse": "npm run build-swapi && npm run build-parse-cloud && npm run build-parse-config",
6763
"build-parse-cloud": "mkdir -p parse/lib/cloud && browserify -p ./scripts/parseify.js node_modules/babel/polyfill parse/src/cloud/main.js > parse/lib/cloud/main.js",
68-
"build-parse-public": "mkdir -p parse/lib/public/graphiql && cp parse/src/public/graphiql/index.html parse/lib/public/graphiql/index.html && cp node_modules/graphiql/graphiql.min.js parse/lib/public/graphiql/graphiql.min.js && cp node_modules/graphiql/graphiql.css parse/lib/public/graphiql/graphiql.css",
6964
"build-parse-config": "mkdir -p parse/lib/config && cp parse/src/config/* parse/lib/config/"
7065
},
7166
"dependencies": {
7267
"babel-runtime": "^5.8.20",
7368
"dataloader": "^1.0.0",
7469
"express": "^4.13.3",
75-
"express-graphql": "^0.3.0",
76-
"graphiql": "0.2.3",
77-
"graphql": "^0.4.0",
70+
"express-graphql": "^0.4.0",
71+
"graphql": "^0.4.5",
7872
"graphql-relay": "^0.3.0",
7973
"isomorphic-fetch": "^2.1.1",
8074
"react": "^0.13.3"

server/src/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ SWAPI Local GraphQL Server
22
==========================
33

44
This directory contains code to run a local `express` server, running
5-
`/graphql` and `/graphiql` on localhost with the SWAPI schema.
5+
on localhost with the SWAPI schema.

server/src/graphiql/index.html

-95
This file was deleted.

server/src/server.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import graphqlHTTP from 'express-graphql';
1111
import swapiSchema from '../../swapi/lib/';
1212

1313
var app = express();
14-
app.use('/graphiql', express.static(path.join(__dirname, 'graphiql')));
15-
app.use('/graphql', graphqlHTTP(() => ({
16-
schema: swapiSchema
14+
15+
// Requests to /graphql redirect to /
16+
app.all('/graphql', (req, res) => res.redirect('/'));
17+
18+
app.use('/', graphqlHTTP(() => ({
19+
schema: swapiSchema,
20+
graphiql: true
1721
})));
22+
1823
var server = app.listen(8080, () => {
1924
console.log(
20-
`GraphQL running on http://localhost:${server.address().port}/graphql`
21-
);
22-
console.log(
23-
`GraphiQL running on http://localhost:${server.address().port}/graphiql`
25+
`GraphQL running on http://localhost:${server.address().port}/`
2426
);
2527
});

0 commit comments

Comments
 (0)