From 4ad8f7ea272bf41aa366bf02cc50c3fdaabef8fb Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Mon, 9 Sep 2024 14:16:58 +0300 Subject: [PATCH 1/2] remove deprecated getFieldDefFn arg to TypeInfo --- src/utilities/TypeInfo.ts | 22 +--------------- src/validation/ValidationContext.ts | 1 - src/validation/__tests__/validation-test.ts | 29 --------------------- 3 files changed, 1 insertion(+), 51 deletions(-) diff --git a/src/utilities/TypeInfo.ts b/src/utilities/TypeInfo.ts index 2fd4765c30..75a4eab9ff 100644 --- a/src/utilities/TypeInfo.ts +++ b/src/utilities/TypeInfo.ts @@ -3,7 +3,6 @@ import type { Maybe } from '../jsutils/Maybe.js'; import type { ASTNode, DocumentNode, - FieldNode, FragmentDefinitionNode, VariableDefinitionNode, } from '../language/ast.js'; @@ -64,7 +63,6 @@ export class TypeInfo { private _fragmentSignature: Maybe; private _fragmentArgument: Maybe; - private _getFieldDef: GetFieldDefFn; constructor( schema: GraphQLSchema, @@ -73,9 +71,6 @@ export class TypeInfo { * beginning somewhere other than documents. */ initialType?: Maybe, - - /** @deprecated will be removed in 17.0.0 */ - getFieldDefFn?: Maybe, fragmentSignatures?: Maybe< (fragmentName: string) => Maybe >, @@ -92,7 +87,6 @@ export class TypeInfo { this._fragmentSignaturesByName = fragmentSignatures ?? (() => null); this._fragmentSignature = null; this._fragmentArgument = null; - this._getFieldDef = getFieldDefFn ?? getFieldDef; if (initialType) { if (isInputType(initialType)) { this._inputTypeStack.push(initialType); @@ -185,7 +179,7 @@ export class TypeInfo { let fieldDef; let fieldType: unknown; if (parentType) { - fieldDef = this._getFieldDef(schema, parentType, node); + fieldDef = schema.getField(parentType, node.name.value); if (fieldDef) { fieldType = fieldDef.type; } @@ -348,20 +342,6 @@ export class TypeInfo { } } -type GetFieldDefFn = ( - schema: GraphQLSchema, - parentType: GraphQLCompositeType, - fieldNode: FieldNode, -) => Maybe>; - -function getFieldDef( - schema: GraphQLSchema, - parentType: GraphQLCompositeType, - fieldNode: FieldNode, -) { - return schema.getField(parentType, fieldNode.name.value); -} - function getFragmentSignatures( document: DocumentNode, ): Map { diff --git a/src/validation/ValidationContext.ts b/src/validation/ValidationContext.ts index 7f881fc369..7f7114c4ef 100644 --- a/src/validation/ValidationContext.ts +++ b/src/validation/ValidationContext.ts @@ -205,7 +205,6 @@ export class ValidationContext extends ASTValidationContext { const typeInfo = new TypeInfo( this._schema, undefined, - undefined, this._typeInfo.getFragmentSignatureByName(), ); const fragmentDefinition = diff --git a/src/validation/__tests__/validation-test.ts b/src/validation/__tests__/validation-test.ts index 19cb3b178a..89f3d20789 100644 --- a/src/validation/__tests__/validation-test.ts +++ b/src/validation/__tests__/validation-test.ts @@ -53,35 +53,6 @@ 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 From d14bc579755329a3b3d704ddc807d66a18851e08 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Mon, 9 Sep 2024 14:25:31 +0300 Subject: [PATCH 2/2] lint --- src/validation/__tests__/validation-test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/validation/__tests__/validation-test.ts b/src/validation/__tests__/validation-test.ts index 89f3d20789..13de153c39 100644 --- a/src/validation/__tests__/validation-test.ts +++ b/src/validation/__tests__/validation-test.ts @@ -9,7 +9,6 @@ import type { DirectiveNode } from '../../language/ast.js'; import { parse } from '../../language/parser.js'; import { buildSchema } from '../../utilities/buildASTSchema.js'; -import { TypeInfo } from '../../utilities/TypeInfo.js'; import { validate } from '../validate.js'; import type { ValidationContext } from '../ValidationContext.js';