Skip to content

Commit 2ec6976

Browse files
committed
[Feature] GraphQL support
1 parent e8232e8 commit 2ec6976

10 files changed

+91
-2
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [x] Deploy with Docker
2424
- [x] Deploy with Docker Compose
2525
- [x] Deploy with one click
26+
- [x] GraphQL support `GRAPHQL_SUPPORT=true`, `GRAPHQL_SCHEMA=YOUR_SCHEMA_URL` (default to `./cloud/graphql/schema.js`)
2627

2728
## :tv: Overview
2829
![Parse Server Diagram](https://github.com/yongjhih/docker-parse-server/raw/master/art/parse-server-diagram.png)
@@ -206,6 +207,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
206207
}
207208
}
208209
```
210+
211+
### :paperclip: GraphQL
212+
Run with GraphQL support.
213+
```shell
214+
GRAPHQL_SUPPORT=true APP_ID=YOUR_APP_ID MASTER_KEY=YOUR_MASTER_KEY SERVER_URL=http://localhost:1337/parse docker-compose up -d
215+
```
216+
> Make sure `./cloud/graphql/schema.js` is pushed to cloud code.
217+
> Then navigate to [http://localhost:1337/graphql?query=%7B%0A%20%20hello%0A%7D%0A](http://localhost:1337/graphql?query=%7B%0A%20%20hello%0A%7D%0A)
218+
219+
![](./art/graphql.png)
220+
209221
## :eyes: See Also
210222
* https://github.com/ParsePlatform/parse-server
211223
* http://blog.parse.com/announcements/introducing-parse-server-and-the-database-migration-tool/

art/graphql.png

51.8 KB
Loading

cloud/graphql/schema.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var graphql = require('graphql')
2+
var GraphQLSchema = graphql.GraphQLSchema
3+
var GraphQLObjectType = graphql.GraphQLObjectType
4+
var GraphQLString = graphql.GraphQLString
5+
6+
module.exports = new GraphQLSchema({
7+
query: new GraphQLObjectType({
8+
name: 'RootQueryType',
9+
fields: {
10+
hello: {
11+
type: GraphQLString,
12+
resolve() {
13+
return 'world';
14+
}
15+
}
16+
}
17+
})
18+
});

dev/cloud/graphql/schema.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var graphql = require('graphql')
2+
var GraphQLSchema = graphql.GraphQLSchema
3+
var GraphQLObjectType = graphql.GraphQLObjectType
4+
var GraphQLString = graphql.GraphQLString
5+
6+
module.exports = new GraphQLSchema({
7+
query: new GraphQLObjectType({
8+
name: 'RootQueryType',
9+
fields: {
10+
hello: {
11+
type: GraphQLString,
12+
resolve() {
13+
return 'world';
14+
}
15+
}
16+
}
17+
})
18+
});

docker-compose-le.yml

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ parse-server:
6161
VIRTUAL_HOST: $PARSE_SERVER_VIRTUAL_HOST
6262
LETSENCRYPT_HOST: $PARSE_SERVER_LETSENCRYPT_HOST
6363
LETSENCRYPT_EMAIL: $PARSE_SERVER_LETSENCRYPT_EMAIL
64+
GRAPHQL_SUPPORT: $GRAPHQL_SUPPORT
65+
GRAPHQL_SCHEMA: $GRAPHQL_SCHEMA
6466
links:
6567
- mongo
6668
volumes_from:

docker-compose-production.yml

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ parse-server:
5858
AZURE_CONTAINER: $AZURE_CONTAINER
5959
AZURE_ACCESS_KEY: $AZURE_ACCESS_KEY
6060
AZURE_DIRECT: $AZURE_DIRECT
61+
GRAPHQL_SUPPORT: $GRAPHQL_SUPPORT
62+
GRAPHQL_SCHEMA: $GRAPHQL_SCHEMA
6163
links:
6264
- mongo
6365
volumes_from:

docker-compose-without-dashboard.yml

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ parse-server:
5757
AZURE_CONTAINER: $AZURE_CONTAINER
5858
AZURE_ACCESS_KEY: $AZURE_ACCESS_KEY
5959
AZURE_DIRECT: $AZURE_DIRECT
60+
GRAPHQL_SUPPORT: $GRAPHQL_SUPPORT
61+
GRAPHQL_SCHEMA: $GRAPHQL_SCHEMA
6062
links:
6163
- mongo
6264
volumes_from:

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ parse-server:
6060
AZURE_DIRECT: $AZURE_DIRECT
6161
LIVEQUERY_SUPPORT: $LIVEQUERY_SUPPORT
6262
LIVEQUERY_CLASSES: $LIVEQUERY_CLASSES
63+
GRAPHQL_SUPPORT: $GRAPHQL_SUPPORT
64+
GRAPHQL_SCHEMA: $GRAPHQL_SCHEMA
6365
links:
6466
- mongo
6567
volumes_from:

index.js

+31
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,34 @@ if(liveQuery) {
272272
console.log('docker-parse-server running on ' + serverURL + ' (:' + port + mountPath + ')');
273273
});
274274
}
275+
276+
// GraphQL
277+
var isSupportGraphQL = process.env.GRAPHQL_SUPPORT;
278+
var schemaURL = process.env.GRAPHQL_SCHEMA || './cloud/graphql/schema.js';
279+
280+
console.log('isSupportGraphQL :', isSupportGraphQL);
281+
console.log('schemaURL :', schemaURL);
282+
283+
if(isSupportGraphQL){
284+
console.log('Starting GraphQL...');
285+
286+
var IS_DEVELOPMENT = process.env.NODE_ENV !== 'production';
287+
288+
function getSchema() {
289+
if (IS_DEVELOPMENT) {
290+
delete require.cache[require.resolve(schemaURL)];
291+
}
292+
293+
return require(schemaURL);
294+
}
295+
296+
var graphQLHTTP = require('express-graphql');
297+
app.use('/graphql', graphQLHTTP(function(request){ return {
298+
graphiql: IS_DEVELOPMENT,
299+
pretty: IS_DEVELOPMENT,
300+
schema: getSchema()
301+
}}));
302+
303+
// TOHAVE : Support custom `./graphql` path and maybe `port`?
304+
isSupportGraphQL && console.log('GraphQL running on ' + serverURL.split(port + mountPath).join(port) + '/graphql');
305+
}

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
"dependencies": {
1212
"docker-links": "^1.0.2",
1313
"express": "~4.11.x",
14+
"express-graphql": "^0.6.1",
15+
"graphql": "^0.8.2",
1416
"kerberos": "~0.0.x",
17+
"mongodb": "2.1.18",
1518
"nodemon": "^1.8.1",
1619
"parse": "~1.8.0",
1720
"parse-server": "2.2.22",
18-
"parse-server-azure-storage": "^1.1.0",
19-
"mongodb":"2.1.18"
21+
"parse-server-azure-storage": "^1.1.0"
2022
},
2123
"scripts": {
2224
"start": "nodemon --watch /parse/cloud index.js"

0 commit comments

Comments
 (0)