GraphQL custom schema on CLI (#5828)

* Add --graphQLSchema to CLI

* Add custom graphql schema instructions to readme file

* Update README.md

Co-Authored-By: Tom Fox <tomfox@surprises.io>

* Update src/Options/Definitions.js

Co-Authored-By: Tom Fox <tomfox@surprises.io>

* Update src/Options/docs.js

Co-Authored-By: Tom Fox <tomfox@surprises.io>

* Update src/Options/index.js

Co-Authored-By: Tom Fox <tomfox@surprises.io>
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-07-19 12:29:45 -07:00
committed by GitHub
parent 6d5f6b4c94
commit a6f441248b
5 changed files with 65 additions and 2 deletions

View File

@@ -158,6 +158,10 @@ module.exports.ParseServerOptions = {
help: 'Mount path for the GraphQL endpoint, defaults to /graphql',
default: '/graphql',
},
graphQLSchema: {
env: 'PARSE_SERVER_GRAPH_QLSCHEMA',
help: 'Full path to your GraphQL custom schema.graphql file',
},
host: {
env: 'PARSE_SERVER_HOST',
help: 'The host to serve ParseServer on, defaults to 0.0.0.0',

View File

@@ -28,6 +28,7 @@
* @property {String} fileKey Key for your files
* @property {Adapter<FilesAdapter>} filesAdapter Adapter module for the files sub-system
* @property {String} graphQLPath Mount path for the GraphQL endpoint, defaults to /graphql
* @property {String} graphQLSchema Full path to your GraphQL custom schema.graphql file
* @property {String} host The host to serve ParseServer on, defaults to 0.0.0.0
* @property {String} javascriptKey Key for the Javascript SDK
* @property {Boolean} jsonLogs Log as structured JSON objects

View File

@@ -180,6 +180,8 @@ export interface ParseServerOptions {
startLiveQueryServer: ?boolean;
/* Live query server configuration options (will start the liveQuery server) */
liveQueryServerOptions: ?LiveQueryServerOptions;
/* Full path to your GraphQL custom schema.graphql file */
graphQLSchema: ?string;
/* Mounts the GraphQL endpoint
:ENV: PARSE_SERVER_MOUNT_GRAPHQL
:DEFAULT: false */

View File

@@ -5,7 +5,9 @@ var batch = require('./batch'),
express = require('express'),
middlewares = require('./middlewares'),
Parse = require('parse/node').Parse,
path = require('path');
{ parse } = require('graphql'),
path = require('path'),
fs = require('fs');
import { ParseServerOptions, LiveQueryServerOptions } from './Options';
import defaults from './defaults';
@@ -267,9 +269,17 @@ class ParseServer {
app.use(options.mountPath, this.app);
if (options.mountGraphQL === true || options.mountPlayground === true) {
let graphQLCustomTypeDefs = undefined;
if (options.graphQLSchema) {
graphQLCustomTypeDefs = parse(
fs.readFileSync(options.graphQLSchema, 'utf8')
);
}
const parseGraphQLServer = new ParseGraphQLServer(this, {
graphQLPath: options.graphQLPath,
playgroundPath: options.playgroundPath,
graphQLCustomTypeDefs,
});
if (options.mountGraphQL) {