Skip to content
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

Revert "Remove deprecate getFieldDefFn argument of TypeInfo const… #3594

Merged
merged 1 commit into from
May 16, 2022
Merged
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
28 changes: 18 additions & 10 deletions src/utilities/TypeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class TypeInfo {
private _directive: Maybe<GraphQLDirective>;
private _argument: Maybe<GraphQLArgument>;
private _enumValue: Maybe<GraphQLEnumValue>;
private _getFieldDef: GetFieldDefFn;

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

/** @deprecated will be removed in 17.0.0 */
getFieldDefFn?: GetFieldDefFn,
) {
this._schema = schema;
this._typeStack = [];
Expand All @@ -71,6 +75,7 @@ export class TypeInfo {
this._directive = null;
this._argument = null;
this._enumValue = null;
this._getFieldDef = getFieldDefFn ?? getFieldDef;
if (initialType) {
if (isInputType(initialType)) {
this._inputTypeStack.push(initialType);
Expand Down Expand Up @@ -155,7 +160,7 @@ export class TypeInfo {
let fieldDef;
let fieldType: unknown;
if (parentType) {
fieldDef = getFieldDef(schema, parentType, node);
fieldDef = this._getFieldDef(schema, parentType, node);
if (fieldDef) {
fieldType = fieldDef.type;
}
Expand Down Expand Up @@ -286,34 +291,37 @@ export class TypeInfo {
}
}

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

/**
* Not exactly the same as the executor's definition of getFieldDef, in this
* statically evaluated environment we do not always have an Object type,
* and need to handle Interface and Union types.
*/
function getFieldDef(
schema: GraphQLSchema,
parentType: GraphQLCompositeType,
parentType: GraphQLType,
fieldNode: FieldNode,
): Maybe<GraphQLField<unknown, unknown>> {
const fieldName = fieldNode.name.value;
const name = fieldNode.name.value;
if (
fieldName === SchemaMetaFieldDef.name &&
name === SchemaMetaFieldDef.name &&
schema.getQueryType() === parentType
) {
return SchemaMetaFieldDef;
}
if (
fieldName === TypeMetaFieldDef.name &&
schema.getQueryType() === parentType
) {
if (name === TypeMetaFieldDef.name && schema.getQueryType() === parentType) {
return TypeMetaFieldDef;
}
if (fieldName === TypeNameMetaFieldDef.name && isCompositeType(parentType)) {
if (name === TypeNameMetaFieldDef.name && isCompositeType(parentType)) {
return TypeNameMetaFieldDef;
}
if (isObjectType(parentType) || isInterfaceType(parentType)) {
return parentType.getFields()[fieldName];
return parentType.getFields()[name];
}
}

Expand Down