|
1 | 1 | import type { Maybe } from '../jsutils/Maybe';
|
2 | 2 | import type { ObjMap } from '../jsutils/ObjMap';
|
3 | 3 |
|
4 |
| -import type { GraphQLError } from '../error/GraphQLError'; |
| 4 | +import type { |
| 5 | + GraphQLError, |
| 6 | + GraphQLErrorExtensions, |
| 7 | +} from '../error/GraphQLError'; |
| 8 | +import { GraphQLValidationError } from '../error/GraphQLError'; |
5 | 9 |
|
6 | 10 | import type {
|
| 11 | + ASTNode, |
7 | 12 | DocumentNode,
|
8 | 13 | FragmentDefinitionNode,
|
9 | 14 | FragmentSpreadNode,
|
@@ -35,6 +40,13 @@ interface VariableUsage {
|
35 | 40 | readonly defaultValue: Maybe<unknown>;
|
36 | 41 | }
|
37 | 42 |
|
| 43 | +interface ValidationReportOptions { |
| 44 | + message: string; |
| 45 | + nodes: ReadonlyArray<ASTNode> | ASTNode; |
| 46 | + originalError?: Error | undefined; |
| 47 | + extensions?: GraphQLErrorExtensions | undefined; |
| 48 | +} |
| 49 | + |
38 | 50 | /**
|
39 | 51 | * An instance of this class is passed as the "this" context to all validators,
|
40 | 52 | * allowing access to commonly useful contextual information from within a
|
@@ -62,10 +74,22 @@ export class ASTValidationContext {
|
62 | 74 | return 'ASTValidationContext';
|
63 | 75 | }
|
64 | 76 |
|
| 77 | + // TODO: when remove change `onError` to use GraphQLValidationError type instead |
| 78 | + /* c8 ignore next 4 */ |
| 79 | + /** @deprecated Use `report` instead, will be removed in v18 */ |
65 | 80 | reportError(error: GraphQLError): void {
|
66 | 81 | this._onError(error);
|
67 | 82 | }
|
68 | 83 |
|
| 84 | + report(options: ValidationReportOptions): void { |
| 85 | + const error = new GraphQLValidationError(options.message, { |
| 86 | + nodes: options.nodes, |
| 87 | + originalError: options.originalError, |
| 88 | + extensions: options.extensions, |
| 89 | + }); |
| 90 | + this._onError(error); |
| 91 | + } |
| 92 | + |
69 | 93 | getDocument(): DocumentNode {
|
70 | 94 | return this._ast;
|
71 | 95 | }
|
|
0 commit comments