-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
How to manually initialise the server with GraphQL #5761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
After adjusting the initialisation code, I've now gotten closer but still blocked // no changes to server config - still has graphql options enabled
const parseServer = ParseServer.start({ ..serverConfig });
const { expressApp } = parseServer;
// .. use expressApp to setup our custom routes However, when we visit
Our I could do with some guidance on this! |
@omairvaiyani I believe you can adjust your original code with the following code: // there is a difference importing ParseServer this way
const { default: ParseServer, ParseGraphQLServer } = require('parse-server');
const parseServer = new ParseServer({ ...serverConfig });
const parseServerApi = parseServer.app;
app.use('/', parseServerApi); // app is your express instance
const {
mountGraphQL,
mountPlayground,
graphQLPath = '/graphql',
playgroundPath = '/playground'
} = serverConfig;
if (mountGraphQL === true || mountPlayground === true) {
const parseGraphQLServer = new ParseGraphQLServer(parseServer, {
graphQLPath,
playgroundPath,
});
if (mountGraphQL) {
parseGraphQLServer.applyGraphQL(app);
}
if (mountPlayground) {
parseGraphQLServer.applyPlayground(app);
}
} |
@douglasmuraoka So in the past few hours I did unearth that there's a difference in importing the GraphQL itself does run though, I can confirm by making post requests to "/graphql", but when visiting "/playground", it simply doesn't hit the route and gets consumed by the parse router. Just to clarify - my current code is effectively identical to the pseudocode you've comment above. |
Okay I've got it! The parse api router must be mounted after using the playground route. Can't tell you why this is, I'll look into but I imagine its a quirk with express? const { default: ParseServer, ParseGraphQLServer } = require('parse-server');
const parseServer = new ParseServer({ ...serverConfig });
const parseServerApi = parseServer.app;
const {
mountGraphQL,
mountPlayground,
graphQLPath = '/graphql',
playgroundPath = '/playground'
} = serverConfig;
if (mountGraphQL === true || mountPlayground === true) {
const parseGraphQLServer = new ParseGraphQLServer(parseServer, {
graphQLPath,
playgroundPath,
});
if (mountGraphQL) {
parseGraphQLServer.applyGraphQL(app);
}
if (mountPlayground) {
parseGraphQLServer.applyPlayground(app);
}
}
app.use('/', parseServerApi); // <-- Moved here |
@davimacedo would be good to document this in the GraphQL guide |
We use Parse Server as a middleware in our express app - we're able to do this alongside manually setting the up the live query server like so:
Our parse server config:
This does not seem to start the graphql server on its own. Digging into the source code, I can see a
ParseServer
instance method called start - which does not get called in the above manner. Is there a more appropriate / modern way to initialise the server that the docs are not caught up with?The text was updated successfully, but these errors were encountered: