GraphQL support via cli (#5697)
* Including GraphQL options in CLI - now it was auto-generated * Improving the way that the headers are passed to the playground * Including README notes about GraphQL * Improving final text
This commit is contained in:
committed by
GitHub
parent
7ffb3b65e0
commit
5bc79cc3db
@@ -76,6 +76,10 @@ class ParseGraphQLServer {
|
||||
renderPlaygroundPage({
|
||||
endpoint: this.config.graphQLPath,
|
||||
subscriptionEndpoint: this.config.subscriptionsPath,
|
||||
headers: {
|
||||
'X-Parse-Application-Id': this.parseServer.config.appId,
|
||||
'X-Parse-Master-Key': this.parseServer.config.masterKey,
|
||||
},
|
||||
})
|
||||
);
|
||||
res.end();
|
||||
|
||||
@@ -153,6 +153,11 @@ module.exports.ParseServerOptions = {
|
||||
help: 'Adapter module for the files sub-system',
|
||||
action: parsers.moduleOrObjectParser,
|
||||
},
|
||||
graphQLPath: {
|
||||
env: 'PARSE_SERVER_GRAPHQL_PATH',
|
||||
help: 'Mount path for the GraphQL endpoint, defaults to /graphql',
|
||||
default: '/graphql',
|
||||
},
|
||||
host: {
|
||||
env: 'PARSE_SERVER_HOST',
|
||||
help: 'The host to serve ParseServer on, defaults to 0.0.0.0',
|
||||
@@ -219,11 +224,23 @@ module.exports.ParseServerOptions = {
|
||||
env: 'PARSE_SERVER_MIDDLEWARE',
|
||||
help: 'middleware for express server, can be string or function',
|
||||
},
|
||||
mountGraphQL: {
|
||||
env: 'PARSE_SERVER_MOUNT_GRAPHQL',
|
||||
help: 'Mounts the GraphQL endpoint',
|
||||
action: parsers.booleanParser,
|
||||
default: false,
|
||||
},
|
||||
mountPath: {
|
||||
env: 'PARSE_SERVER_MOUNT_PATH',
|
||||
help: 'Mount path for the server, defaults to /parse',
|
||||
default: '/parse',
|
||||
},
|
||||
mountPlayground: {
|
||||
env: 'PARSE_SERVER_MOUNT_PLAYGROUND',
|
||||
help: 'Mounts the GraphQL Playground - never use this option in production',
|
||||
action: parsers.booleanParser,
|
||||
default: false,
|
||||
},
|
||||
objectIdSize: {
|
||||
env: 'PARSE_SERVER_OBJECT_ID_SIZE',
|
||||
help: "Sets the number of characters in generated object id's, default 10",
|
||||
@@ -235,6 +252,11 @@ module.exports.ParseServerOptions = {
|
||||
help: 'Password policy for enforcing password related rules',
|
||||
action: parsers.objectParser,
|
||||
},
|
||||
playgroundPath: {
|
||||
env: 'PARSE_SERVER_PLAYGROUND_PATH',
|
||||
help: 'Mount path for the GraphQL Playground, defaults to /playground',
|
||||
default: '/playground',
|
||||
},
|
||||
port: {
|
||||
env: 'PORT',
|
||||
help: 'The port to run the ParseServer, defaults to 1337.',
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
* @property {Boolean} expireInactiveSessions Sets wether we should expire the inactive sessions, defaults to true
|
||||
* @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} 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
|
||||
@@ -40,9 +41,12 @@
|
||||
* @property {Number} maxLimit Max value for limit option on queries, defaults to unlimited
|
||||
* @property {String} maxUploadSize Max file size for uploads, defaults to 20mb
|
||||
* @property {Union} middleware middleware for express server, can be string or function
|
||||
* @property {Boolean} mountGraphQL Mounts the GraphQL endpoint
|
||||
* @property {String} mountPath Mount path for the server, defaults to /parse
|
||||
* @property {Boolean} mountPlayground Mounts the GraphQL Playground - never use this option in production
|
||||
* @property {Number} objectIdSize Sets the number of characters in generated object id's, default 10
|
||||
* @property {Any} passwordPolicy Password policy for enforcing password related rules
|
||||
* @property {String} playgroundPath Mount path for the GraphQL Playground, defaults to /playground
|
||||
* @property {Number} port The port to run the ParseServer, defaults to 1337.
|
||||
* @property {Boolean} preserveFileName Enable (or disable) the addition of a unique hash to the file names
|
||||
* @property {Boolean} preventLoginWithUnverifiedEmail Prevent user from login if email is not verified and PARSE_SERVER_VERIFY_USER_EMAILS is true, defaults to false
|
||||
|
||||
@@ -180,6 +180,22 @@ export interface ParseServerOptions {
|
||||
startLiveQueryServer: ?boolean;
|
||||
/* Live query server configuration options (will start the liveQuery server) */
|
||||
liveQueryServerOptions: ?LiveQueryServerOptions;
|
||||
/* Mounts the GraphQL endpoint
|
||||
:ENV: PARSE_SERVER_MOUNT_GRAPHQL
|
||||
:DEFAULT: false */
|
||||
mountGraphQL: ?boolean;
|
||||
/* Mount path for the GraphQL endpoint, defaults to /graphql
|
||||
:ENV: PARSE_SERVER_GRAPHQL_PATH
|
||||
:DEFAULT: /graphql */
|
||||
graphQLPath: ?string;
|
||||
/* Mounts the GraphQL Playground - never use this option in production
|
||||
:ENV: PARSE_SERVER_MOUNT_PLAYGROUND
|
||||
:DEFAULT: false */
|
||||
mountPlayground: ?boolean;
|
||||
/* Mount path for the GraphQL Playground, defaults to /playground
|
||||
:ENV: PARSE_SERVER_PLAYGROUND_PATH
|
||||
:DEFAULT: /playground */
|
||||
playgroundPath: ?string;
|
||||
|
||||
serverStartComplete: ?(error: ?Error) => void;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,10 @@ import { UsersRouter } from './Routers/UsersRouter';
|
||||
import { PurgeRouter } from './Routers/PurgeRouter';
|
||||
import { AudiencesRouter } from './Routers/AudiencesRouter';
|
||||
import { AggregateRouter } from './Routers/AggregateRouter';
|
||||
|
||||
import { ParseServerRESTController } from './ParseServerRESTController';
|
||||
import * as controllers from './Controllers';
|
||||
import { ParseGraphQLServer } from './GraphQL/ParseGraphQLServer';
|
||||
|
||||
// Mutate the Parse object to add the Cloud Code handlers
|
||||
addParseCloud();
|
||||
|
||||
@@ -264,6 +265,22 @@ class ParseServer {
|
||||
}
|
||||
|
||||
app.use(options.mountPath, this.app);
|
||||
|
||||
if (options.mountGraphQL === true || options.mountPlayground === true) {
|
||||
const parseGraphQLServer = new ParseGraphQLServer(this, {
|
||||
graphQLPath: options.graphQLPath,
|
||||
playgroundPath: options.playgroundPath,
|
||||
});
|
||||
|
||||
if (options.mountGraphQL) {
|
||||
parseGraphQLServer.applyGraphQL(app);
|
||||
}
|
||||
|
||||
if (options.mountPlayground) {
|
||||
parseGraphQLServer.applyPlayground(app);
|
||||
}
|
||||
}
|
||||
|
||||
const server = app.listen(options.port, options.host, callback);
|
||||
this.server = server;
|
||||
|
||||
|
||||
@@ -84,20 +84,40 @@ runner({
|
||||
});
|
||||
} else {
|
||||
ParseServer.start(options, () => {
|
||||
console.log(
|
||||
'[' + process.pid + '] parse-server running on ' + options.serverURL
|
||||
);
|
||||
printSuccessMessage();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ParseServer.start(options, () => {
|
||||
logOptions();
|
||||
console.log('');
|
||||
console.log(
|
||||
'[' + process.pid + '] parse-server running on ' + options.serverURL
|
||||
);
|
||||
printSuccessMessage();
|
||||
});
|
||||
}
|
||||
|
||||
function printSuccessMessage() {
|
||||
console.log(
|
||||
'[' + process.pid + '] parse-server running on ' + options.serverURL
|
||||
);
|
||||
if (options.mountGraphQL) {
|
||||
console.log(
|
||||
'[' +
|
||||
process.pid +
|
||||
'] GraphQL running on http://localhost:' +
|
||||
options.port +
|
||||
options.graphQLPath
|
||||
);
|
||||
}
|
||||
if (options.mountPlayground) {
|
||||
console.log(
|
||||
'[' +
|
||||
process.pid +
|
||||
'] Playground running on http://localhost:' +
|
||||
options.port +
|
||||
options.playgroundPath
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user