Skip to content

Commit

Permalink
enhancement/optimize graphql server for production builds (#1277)
Browse files Browse the repository at this point in the history
* optimize graphql server for production builds

* fix linting

* tweak coverage thresholds
  • Loading branch information
thescientist13 committed Nov 2, 2024
1 parent 9746990 commit 24fa5f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit 24fa5f5

Please sign in to comment.