ValidationContext.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import type { Maybe } from '../jsutils/Maybe';
  2. import type { GraphQLError } from '../error/GraphQLError';
  3. import type {
  4. DocumentNode,
  5. FragmentDefinitionNode,
  6. FragmentSpreadNode,
  7. OperationDefinitionNode,
  8. SelectionSetNode,
  9. VariableNode,
  10. } from '../language/ast';
  11. import type { ASTVisitor } from '../language/visitor';
  12. import type {
  13. GraphQLArgument,
  14. GraphQLCompositeType,
  15. GraphQLEnumValue,
  16. GraphQLField,
  17. GraphQLInputType,
  18. GraphQLOutputType,
  19. } from '../type/definition';
  20. import type { GraphQLDirective } from '../type/directives';
  21. import type { GraphQLSchema } from '../type/schema';
  22. import { TypeInfo } from '../utilities/TypeInfo';
  23. declare type NodeWithSelectionSet =
  24. | OperationDefinitionNode
  25. | FragmentDefinitionNode;
  26. interface VariableUsage {
  27. readonly node: VariableNode;
  28. readonly type: Maybe<GraphQLInputType>;
  29. readonly defaultValue: Maybe<unknown>;
  30. }
  31. /**
  32. * An instance of this class is passed as the "this" context to all validators,
  33. * allowing access to commonly useful contextual information from within a
  34. * validation rule.
  35. */
  36. export declare class ASTValidationContext {
  37. private _ast;
  38. private _onError;
  39. private _fragments;
  40. private _fragmentSpreads;
  41. private _recursivelyReferencedFragments;
  42. constructor(ast: DocumentNode, onError: (error: GraphQLError) => void);
  43. get [Symbol.toStringTag](): string;
  44. reportError(error: GraphQLError): void;
  45. getDocument(): DocumentNode;
  46. getFragment(name: string): Maybe<FragmentDefinitionNode>;
  47. getFragmentSpreads(node: SelectionSetNode): ReadonlyArray<FragmentSpreadNode>;
  48. getRecursivelyReferencedFragments(
  49. operation: OperationDefinitionNode,
  50. ): ReadonlyArray<FragmentDefinitionNode>;
  51. }
  52. export declare type ASTValidationRule = (
  53. context: ASTValidationContext,
  54. ) => ASTVisitor;
  55. export declare class SDLValidationContext extends ASTValidationContext {
  56. private _schema;
  57. constructor(
  58. ast: DocumentNode,
  59. schema: Maybe<GraphQLSchema>,
  60. onError: (error: GraphQLError) => void,
  61. );
  62. get [Symbol.toStringTag](): string;
  63. getSchema(): Maybe<GraphQLSchema>;
  64. }
  65. export declare type SDLValidationRule = (
  66. context: SDLValidationContext,
  67. ) => ASTVisitor;
  68. export declare class ValidationContext extends ASTValidationContext {
  69. private _schema;
  70. private _typeInfo;
  71. private _variableUsages;
  72. private _recursiveVariableUsages;
  73. constructor(
  74. schema: GraphQLSchema,
  75. ast: DocumentNode,
  76. typeInfo: TypeInfo,
  77. onError: (error: GraphQLError) => void,
  78. );
  79. get [Symbol.toStringTag](): string;
  80. getSchema(): GraphQLSchema;
  81. getVariableUsages(node: NodeWithSelectionSet): ReadonlyArray<VariableUsage>;
  82. getRecursiveVariableUsages(
  83. operation: OperationDefinitionNode,
  84. ): ReadonlyArray<VariableUsage>;
  85. getType(): Maybe<GraphQLOutputType>;
  86. getParentType(): Maybe<GraphQLCompositeType>;
  87. getInputType(): Maybe<GraphQLInputType>;
  88. getParentInputType(): Maybe<GraphQLInputType>;
  89. getFieldDef(): Maybe<GraphQLField<unknown, unknown>>;
  90. getDirective(): Maybe<GraphQLDirective>;
  91. getArgument(): Maybe<GraphQLArgument>;
  92. getEnumValue(): Maybe<GraphQLEnumValue>;
  93. }
  94. export declare type ValidationRule = (context: ValidationContext) => ASTVisitor;
  95. export {};