Skip to content

Commit

Permalink
ValidationContext: Remove deprecated 'getErrors' and make 'onEr… (#2130)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Sep 15, 2019
1 parent a7cc223 commit dd6dd3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
18 changes: 4 additions & 14 deletions src/validation/ValidationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,24 @@ type VariableUsage = {|
*/
export class ASTValidationContext {
_ast: DocumentNode;
_onError: ?(err: GraphQLError) => void;
_errors: Array<GraphQLError>;
_onError: (err: GraphQLError) => void;
_fragments: ?ObjMap<FragmentDefinitionNode>;
_fragmentSpreads: Map<SelectionSetNode, $ReadOnlyArray<FragmentSpreadNode>>;
_recursivelyReferencedFragments: Map<
OperationDefinitionNode,
$ReadOnlyArray<FragmentDefinitionNode>,
>;

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();
this._onError = onError;
}

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<GraphQLError> {
return this._errors;
this._onError(error);
}

getDocument(): DocumentNode {
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions tstypes/validation/ValidationContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphQLError>;

getDocument(): DocumentNode;

getFragment(name: string): Maybe<FragmentDefinitionNode>;
Expand All @@ -54,7 +52,7 @@ export class SDLValidationContext extends ASTValidationContext {
constructor(
ast: DocumentNode,
schema: Maybe<GraphQLSchema>,
onError?: (err: GraphQLError) => void,
onError: (err: GraphQLError) => void,
);

getSchema(): Maybe<GraphQLSchema>;
Expand All @@ -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;
Expand Down

0 comments on commit dd6dd3c

Please sign in to comment.