Skip to content

Commit

Permalink
validate: remove warning about throwing literal (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 26, 2022
1 parent ac90b52 commit 5aadd61
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/validation/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,17 @@ export function validate(
// If the schema used for validation is invalid, throw an error.
assertValidSchema(schema);

const abortObj = Object.freeze({});
const abortError = new GraphQLError(
'Too many validation errors, error limit reached. Validation aborted.',
);
const errors: Array<GraphQLError> = [];
const context = new ValidationContext(
schema,
documentAST,
typeInfo,
(error) => {
if (errors.length >= maxErrors) {
errors.push(
new GraphQLError(
'Too many validation errors, error limit reached. Validation aborted.',
),
);
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw abortObj;
throw abortError;
}
errors.push(error);
},
Expand All @@ -75,8 +71,10 @@ export function validate(
// Visit the whole document with each instance of all provided rules.
try {
visit(documentAST, visitWithTypeInfo(typeInfo, visitor));
} catch (e) {
if (e !== abortObj) {
} catch (e: unknown) {
if (e === abortError) {
errors.push(abortError);
} else {
throw e;
}
}
Expand Down

0 comments on commit 5aadd61

Please sign in to comment.