Skip to content

remove deprecated getFieldDefFn arg to TypeInfo #4186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions src/utilities/TypeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Maybe } from '../jsutils/Maybe.js';
import type {
ASTNode,
DocumentNode,
FieldNode,
FragmentDefinitionNode,
VariableDefinitionNode,
} from '../language/ast.js';
Expand Down Expand Up @@ -64,7 +63,6 @@ export class TypeInfo {

private _fragmentSignature: Maybe<FragmentSignature>;
private _fragmentArgument: Maybe<VariableDefinitionNode>;
private _getFieldDef: GetFieldDefFn;

constructor(
schema: GraphQLSchema,
Expand All @@ -73,9 +71,6 @@ export class TypeInfo {
* beginning somewhere other than documents.
*/
initialType?: Maybe<GraphQLType>,

/** @deprecated will be removed in 17.0.0 */
getFieldDefFn?: Maybe<GetFieldDefFn>,
fragmentSignatures?: Maybe<
(fragmentName: string) => Maybe<FragmentSignature>
>,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -348,20 +342,6 @@ export class TypeInfo {
}
}

type GetFieldDefFn = (
schema: GraphQLSchema,
parentType: GraphQLCompositeType,
fieldNode: FieldNode,
) => Maybe<GraphQLField<unknown, unknown>>;

function getFieldDef(
schema: GraphQLSchema,
parentType: GraphQLCompositeType,
fieldNode: FieldNode,
) {
return schema.getField(parentType, fieldNode.name.value);
}

function getFragmentSignatures(
document: DocumentNode,
): Map<string, FragmentSignature> {
Expand Down
1 change: 0 additions & 1 deletion src/validation/ValidationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export class ValidationContext extends ASTValidationContext {
const typeInfo = new TypeInfo(
this._schema,
undefined,
undefined,
this._typeInfo.getFragmentSignatureByName(),
);
const fragmentDefinition =
Expand Down
30 changes: 0 additions & 30 deletions src/validation/__tests__/validation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -53,35 +52,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
Expand Down
Loading