Skip to content
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

enhancement/optimize graphql server for production builds #1277

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

"checkCoverage": true,

"statements": 80,
"statements": 75,
"branches": 85,
"functions": 85,
"lines": 80,
"lines": 75,

"watermarks": {
"statements": [75, 85],
Expand Down
20 changes: 14 additions & 6 deletions packages/plugin-graphql/src/core/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@ import { ApolloServer } from 'apollo-server';

const graphqlServer = async (compilation) => {
const { config, graph, context } = compilation;
const isDev = process.env.__GWD_COMMAND__ === 'develop'; // eslint-disable-line no-underscore-dangle
const { createSchema } = await import('../schema/schema.js');
const { createCache } = await import('./cache.js');

const server = new ApolloServer({
schema: await createSchema(compilation),
playground: {
// disable playground for production builds
const playground = isDev ?
{
endpoint: '/graphql',
settings: {
'editor.theme': 'light'
}
},
}
: {};

const server = new ApolloServer({
schema: await createSchema(compilation),
playground,
introspection: isDev,
context: async (integrationContext) => {
const { req } = integrationContext;

if (req.query.q !== 'internal') {
// make sure to ignore introspection requests from being generated as an output cache file
// https://stackoverflow.com/a/58040379/417806
if (req.query.q !== 'internal' && req.body.operationName !== 'IntrospectionQuery') {
await createCache(req, context);
}

Expand Down
Loading