@@ -8,21 +8,21 @@ import { Kind } from '../language/kinds';
8
8
import { type ASTVisitor , visit , visitWithTypeInfo } from '../language/visitor' ;
9
9
import {
10
10
type DocumentNode ,
11
+ type FragmentDefinitionNode ,
12
+ type FragmentSpreadNode ,
11
13
type OperationDefinitionNode ,
12
- type VariableNode ,
13
14
type SelectionSetNode ,
14
- type FragmentSpreadNode ,
15
- type FragmentDefinitionNode ,
15
+ type VariableNode ,
16
16
} from '../language/ast' ;
17
17
18
18
import { type GraphQLSchema } from '../type/schema' ;
19
19
import { type GraphQLDirective } from '../type/directives' ;
20
20
import {
21
- type GraphQLInputType ,
22
- type GraphQLOutputType ,
21
+ type GraphQLArgument ,
23
22
type GraphQLCompositeType ,
24
23
type GraphQLField ,
25
- type GraphQLArgument ,
24
+ type GraphQLInputType ,
25
+ type GraphQLOutputType ,
26
26
} from '../type/definition' ;
27
27
28
28
import { TypeInfo } from '../utilities/TypeInfo' ;
@@ -41,6 +41,7 @@ type VariableUsage = {|
41
41
*/
42
42
export class ASTValidationContext {
43
43
_ast : DocumentNode ;
44
+ _onError: ?( err : Error ) => void = undefined ;
44
45
_errors: Array < GraphQLError > ;
45
46
_fragments: ?ObjMap < FragmentDefinitionNode > ;
46
47
_fragmentSpreads: Map < SelectionSetNode , $ReadOnlyArray < FragmentSpreadNode >> ;
@@ -49,16 +50,22 @@ export class ASTValidationContext {
49
50
$ReadOnlyArray < FragmentDefinitionNode > ,
50
51
> ;
51
52
52
- constructor ( ast : DocumentNode ) : void {
53
+ constructor ( ast : DocumentNode , onError ?: ( err : Error ) => void ) : void {
53
54
this. _ast = ast ;
54
55
this . _errors = [ ] ;
55
56
this . _fragments = undefined ;
56
57
this . _fragmentSpreads = new Map ( ) ;
57
58
this . _recursivelyReferencedFragments = new Map ( ) ;
59
+ if ( onError ) {
60
+ this . _onError = onError . bind ( this ) ;
61
+ }
58
62
}
59
63
60
64
reportError ( error : GraphQLError ) : void {
61
65
this. _errors . push ( error ) ;
66
+ if ( this . _onError ) {
67
+ this . _onError ( error ) ;
68
+ }
62
69
}
63
70
64
71
getErrors ( ) : $ReadOnlyArray < GraphQLError > {
@@ -165,8 +172,9 @@ export class ValidationContext extends ASTValidationContext {
165
172
schema : GraphQLSchema ,
166
173
ast : DocumentNode ,
167
174
typeInfo : TypeInfo ,
175
+ onError ?: ( err : Error ) => void ,
168
176
) : void {
169
- super ( ast ) ;
177
+ super ( ast , onError ) ;
170
178
this . _schema = schema ;
171
179
this . _typeInfo = typeInfo ;
172
180
this . _variableUsages = new Map ( ) ;
0 commit comments