Repository: graphql/graphql-js
Pull request #3595 (2022-05-16 20:41:09)

Revert "Remove deprecated `TypeInfo` argument of `validate` function"
This reverts commit b4ad1282ce38449a953d9375307c9e45f8151a70 from #3574
For the context see #3519

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *compassionate-pike-271cb3* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 1d74208b021140d1bc44627c3a29a58f9ad552b1 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/6282b6e7e6f0bb0009cdc6bc |
github-actions[bot]: Hi @IvanGoncharov, I'm @github-actions bot happy to help you with this PR 👋

<details>
<summary> Supported commands </summary>

Please post this commands in separate comments and only one per comment:
* `@github-actions run-benchmark` - Run benchmark comparing base and merge commits for this PR
* `@github-actions publish-pr-on-npm` - Build package from this PR and publish it on NPM
</details>


Patch:
diff --git a/src/validation/validate.ts b/src/validation/validate.ts
index 7fb62736..61ec1412 100644
--- a/src/validation/validate.ts
+++ b/src/validation/validate.ts
@@ -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;
 
@@ -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,


Test patch:
diff --git a/src/validation/__tests__/validation-test.ts b/src/validation/__tests__/validation-test.ts
index 1ef00192..2d49f933 100644
--- a/src/validation/__tests__/validation-test.ts
+++ b/src/validation/__tests__/validation-test.ts
@@ -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';
@@ -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