From e6bfe00843e50f28295869729c2445d47aa433f5 Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Fri, 23 Oct 2020 11:11:39 -0400 Subject: [PATCH 1/2] add cross-env to build scripts --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 93aa5d7921..2b7066c24d 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ }, "scripts": { "build:components": "webpack --config src/webpack/components.config.js", - "build": "PAYLOAD_CONFIG_PATH=demo/payload.config.js node src/bin/build", - "build:analyze": "PAYLOAD_CONFIG_PATH=demo/payload.config.js PAYLOAD_ANALYZE_BUNDLE=true node src/bin/build", + "build": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.js node src/bin/build", + "build:analyze": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.js PAYLOAD_ANALYZE_BUNDLE=true node src/bin/build", "cov": "npm run core:build && node ./node_modules/jest/bin/jest.js src/tests --coverage", "debug": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.js nodemon --inspect demo/server.js", "debug:test:int": "node --inspect-brk node_modules/.bin/jest --runInBand", From e233551d0baf73388aff6241b44d8fb4c2bb4ede Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Fri, 23 Oct 2020 13:11:16 -0400 Subject: [PATCH 2/2] cleanup graphql init --- src/graphql/index.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/graphql/index.js b/src/graphql/index.js index ae8b966ca5..86fbd82d4b 100644 --- a/src/graphql/index.js +++ b/src/graphql/index.js @@ -98,10 +98,22 @@ class InitializeGraphQL { const { result } = info; if (result.errors) { const afterErrorHook = typeof this.config.hooks.afterError === 'function' ? this.config.hooks.afterError : null; - this.errorResponse = await errorHandler(info, this.config.debug, afterErrorHook); + [this.errorResponse] = await errorHandler(info, this.config.debug, afterErrorHook); } return null; }; + this.customFormatErrorFn = () => (this.errorResponse); + this.validationRules = (variables) => ([ + queryComplexity({ + estimators: [ + fieldExtensionsEstimator(), + simpleEstimator({ defaultComplexity: 1 }), // Fallback if complexity not set + ], + maximumComplexity: this.config.graphQL.maxComplexity, + variables, + // onComplete: (complexity) => { console.log('Query Complexity:', complexity); }, + }), + ]); } init(req, res) { @@ -109,20 +121,10 @@ class InitializeGraphQL { return graphQLHTTP( async (request, response, { variables }) => ({ schema: this.schema, - customFormatErrorFn: () => (this.errorResponse), + customFormatErrorFn: this.customFormatErrorFn, extensions: this.extensions, context: { req, res }, - validationRules: [ - queryComplexity({ - estimators: [ - fieldExtensionsEstimator(), - simpleEstimator({ defaultComplexity: 1 }), // Fallback if complexity not set - ], - maximumComplexity: this.config.graphQL.maxComplexity, - variables, - // onComplete: (complexity) => { console.log('Query Complexity:', complexity); }, - }), - ], + validationRules: this.validationRules(variables), }), ); }