diff --git a/package.json b/package.json index a2aec2ff91..c71b78c844 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", 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), }), ); }