Skip to content

Commit 75635f0

Browse files
Revert "Remove deprecated TypeInfo argument of validate function" (#3595)
1 parent e3ac35c commit 75635f0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/validation/__tests__/validation-test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { DirectiveNode } from '../../language/ast';
99
import { parse } from '../../language/parser';
1010

1111
import { buildSchema } from '../../utilities/buildASTSchema';
12+
import { TypeInfo } from '../../utilities/TypeInfo';
1213

1314
import { validate } from '../validate';
1415
import type { ValidationContext } from '../ValidationContext';
@@ -57,6 +58,35 @@ describe('Validate: Supports full validation', () => {
5758
]);
5859
});
5960

61+
it('Deprecated: validates using a custom TypeInfo', () => {
62+
// This TypeInfo will never return a valid field.
63+
const typeInfo = new TypeInfo(testSchema, null, () => null);
64+
65+
const doc = parse(`
66+
query {
67+
human {
68+
pets {
69+
... on Cat {
70+
meowsVolume
71+
}
72+
... on Dog {
73+
barkVolume
74+
}
75+
}
76+
}
77+
}
78+
`);
79+
80+
const errors = validate(testSchema, doc, undefined, undefined, typeInfo);
81+
const errorMessages = errors.map((error) => error.message);
82+
83+
expect(errorMessages).to.deep.equal([
84+
'Cannot query field "human" on type "QueryRoot". Did you mean "human"?',
85+
'Cannot query field "meowsVolume" on type "Cat". Did you mean "meowsVolume"?',
86+
'Cannot query field "barkVolume" on type "Dog". Did you mean "barkVolume"?',
87+
]);
88+
});
89+
6090
it('validates using a custom rule', () => {
6191
const schema = buildSchema(`
6292
directive @custom(arg: String) on FIELD

src/validation/validate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export function validate(
4040
documentAST: DocumentNode,
4141
rules: ReadonlyArray<ValidationRule> = specifiedRules,
4242
options?: { maxErrors?: number },
43+
44+
/** @deprecated will be removed in 17.0.0 */
45+
typeInfo: TypeInfo = new TypeInfo(schema),
4346
): ReadonlyArray<GraphQLError> {
4447
const maxErrors = options?.maxErrors ?? 100;
4548

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

5053
const abortObj = Object.freeze({});
5154
const errors: Array<GraphQLError> = [];
52-
const typeInfo = new TypeInfo(schema);
5355
const context = new ValidationContext(
5456
schema,
5557
documentAST,

0 commit comments

Comments
 (0)