Skip to content

Commit

Permalink
Revert "Remove deprecated TypeInfo argument of validate function" (
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 16, 2022
1 parent e3ac35c commit 75635f0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/validation/__tests__/validation-test.ts
Expand Up @@ -9,6 +9,7 @@ import type { DirectiveNode } from '../../language/ast';
import { parse } from '../../language/parser';

import { buildSchema } from '../../utilities/buildASTSchema';
import { TypeInfo } from '../../utilities/TypeInfo';

import { validate } from '../validate';
import type { ValidationContext } from '../ValidationContext';
Expand Down Expand Up @@ -57,6 +58,35 @@ describe('Validate: Supports full validation', () => {
]);
});

it('Deprecated: validates using a custom TypeInfo', () => {
// This TypeInfo will never return a valid field.
const typeInfo = new TypeInfo(testSchema, null, () => null);

const doc = parse(`
query {
human {
pets {
... on Cat {
meowsVolume
}
... on Dog {
barkVolume
}
}
}
}
`);

const errors = validate(testSchema, doc, undefined, undefined, typeInfo);
const errorMessages = errors.map((error) => error.message);

expect(errorMessages).to.deep.equal([
'Cannot query field "human" on type "QueryRoot". Did you mean "human"?',
'Cannot query field "meowsVolume" on type "Cat". Did you mean "meowsVolume"?',
'Cannot query field "barkVolume" on type "Dog". Did you mean "barkVolume"?',
]);
});

it('validates using a custom rule', () => {
const schema = buildSchema(`
directive @custom(arg: String) on FIELD
Expand Down
4 changes: 3 additions & 1 deletion src/validation/validate.ts
Expand Up @@ -40,6 +40,9 @@ export function validate(
documentAST: DocumentNode,
rules: ReadonlyArray<ValidationRule> = specifiedRules,
options?: { maxErrors?: number },

/** @deprecated will be removed in 17.0.0 */
typeInfo: TypeInfo = new TypeInfo(schema),
): ReadonlyArray<GraphQLError> {
const maxErrors = options?.maxErrors ?? 100;

Expand All @@ -49,7 +52,6 @@ export function validate(

const abortObj = Object.freeze({});
const errors: Array<GraphQLError> = [];
const typeInfo = new TypeInfo(schema);
const context = new ValidationContext(
schema,
documentAST,
Expand Down

0 comments on commit 75635f0

Please sign in to comment.