From 9e31d621bb94e593819bb9bd4d27b50cbf66fbd1 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 26 Aug 2019 13:24:34 +0300 Subject: [PATCH] ValidationContext: Remove deprecated 'getErrors' and make 'onError' required --- src/validation/ValidationContext.js | 18 ++++-------------- tstypes/validation/ValidationContext.d.ts | 8 +++----- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/validation/ValidationContext.js b/src/validation/ValidationContext.js index a3a7bd0f08..abd1c979cb 100644 --- a/src/validation/ValidationContext.js +++ b/src/validation/ValidationContext.js @@ -41,8 +41,7 @@ type VariableUsage = {| */ export class ASTValidationContext { _ast: DocumentNode; - _onError: ?(err: GraphQLError) => void; - _errors: Array; + _onError: (err: GraphQLError) => void; _fragments: ?ObjMap; _fragmentSpreads: Map>; _recursivelyReferencedFragments: Map< @@ -50,9 +49,8 @@ export class ASTValidationContext { $ReadOnlyArray, >; - constructor(ast: DocumentNode, onError?: (err: GraphQLError) => void): void { + constructor(ast: DocumentNode, onError: (err: GraphQLError) => void): void { this._ast = ast; - this._errors = []; this._fragments = undefined; this._fragmentSpreads = new Map(); this._recursivelyReferencedFragments = new Map(); @@ -60,15 +58,7 @@ export class ASTValidationContext { } reportError(error: GraphQLError): void { - this._errors.push(error); - if (this._onError) { - this._onError(error); - } - } - - // @deprecated: use onError callback instead - will be removed in v15. - getErrors(): $ReadOnlyArray { - return this._errors; + this._onError(error); } getDocument(): DocumentNode { @@ -175,7 +165,7 @@ export class ValidationContext extends ASTValidationContext { schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo, - onError?: (err: GraphQLError) => void, + onError: (err: GraphQLError) => void, ): void { super(ast, onError); this._schema = schema; diff --git a/tstypes/validation/ValidationContext.d.ts b/tstypes/validation/ValidationContext.d.ts index b98c947b7f..d5e1c8d03f 100644 --- a/tstypes/validation/ValidationContext.d.ts +++ b/tstypes/validation/ValidationContext.d.ts @@ -33,12 +33,10 @@ type VariableUsage = { * validation rule. */ export class ASTValidationContext { - constructor(ast: DocumentNode); + constructor(ast: DocumentNode, onError: (err: GraphQLError) => void); reportError(error: GraphQLError): undefined; - getErrors(): ReadonlyArray; - getDocument(): DocumentNode; getFragment(name: string): Maybe; @@ -54,7 +52,7 @@ export class SDLValidationContext extends ASTValidationContext { constructor( ast: DocumentNode, schema: Maybe, - onError?: (err: GraphQLError) => void, + onError: (err: GraphQLError) => void, ); getSchema(): Maybe; @@ -67,7 +65,7 @@ export class ValidationContext extends ASTValidationContext { schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo, - onError?: (err: GraphQLError) => void, + onError: (err: GraphQLError) => void, ); getSchema(): GraphQLSchema;