Merge pull request #428 from trouble/rest-gql-errors

Rest gql errors
This commit is contained in:
Dan Ribbens
2020-10-23 13:12:40 -04:00
committed by GitHub
2 changed files with 17 additions and 15 deletions

View File

@@ -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),
}),
);
}