Skip to content

Commit

Permalink
GraphQL*Type: bind only single property instead of entire context (#3876
Browse files Browse the repository at this point in the history
)
  • Loading branch information
IvanGoncharov authored Apr 4, 2023
1 parent 74e51d7 commit ea10c7b
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,8 @@ export class GraphQLObjectType<TSource = any, TContext = any> {

// prettier-ignore
// FIXME: blocked by https://github.com/prettier/prettier/issues/14625
this._fields = (defineFieldMap<TSource, TContext>).bind(undefined, config);
this._interfaces = defineInterfaces.bind(undefined, config);
this._fields = (defineFieldMap<TSource, TContext>).bind(undefined, config.fields);
this._interfaces = defineInterfaces.bind(undefined, config.interfaces);
}

get [Symbol.toStringTag]() {
Expand Down Expand Up @@ -766,20 +766,15 @@ export class GraphQLObjectType<TSource = any, TContext = any> {
}

function defineInterfaces(
config: Readonly<
GraphQLObjectTypeConfig<any, any> | GraphQLInterfaceTypeConfig<any, any>
>,
interfaces: Maybe<ThunkReadonlyArray<GraphQLInterfaceType>>,
): ReadonlyArray<GraphQLInterfaceType> {
return resolveReadonlyArrayThunk(config.interfaces ?? []);
return resolveReadonlyArrayThunk(interfaces ?? []);
}

function defineFieldMap<TSource, TContext>(
config: Readonly<
| GraphQLObjectTypeConfig<TSource, TContext>
| GraphQLInterfaceTypeConfig<TSource, TContext>
>,
fields: ThunkObjMap<GraphQLFieldConfig<TSource, TContext>>,
): GraphQLFieldMap<TSource, TContext> {
const fieldMap = resolveObjMapThunk(config.fields);
const fieldMap = resolveObjMapThunk(fields);

return mapValue(fieldMap, (fieldConfig, fieldName) => {
const argsConfig = fieldConfig.args ?? {};
Expand All @@ -798,9 +793,9 @@ function defineFieldMap<TSource, TContext>(
}

export function defineArguments(
config: GraphQLFieldConfigArgumentMap,
args: GraphQLFieldConfigArgumentMap,
): ReadonlyArray<GraphQLArgument> {
return Object.entries(config).map(([argName, argConfig]) => ({
return Object.entries(args).map(([argName, argConfig]) => ({
name: assertName(argName),
description: argConfig.description,
type: argConfig.type,
Expand Down Expand Up @@ -1041,8 +1036,8 @@ export class GraphQLInterfaceType {
this.astNode = config.astNode;
this.extensionASTNodes = config.extensionASTNodes ?? [];

this._fields = defineFieldMap.bind(undefined, config);
this._interfaces = defineInterfaces.bind(undefined, config);
this._fields = defineFieldMap.bind(undefined, config.fields);
this._interfaces = defineInterfaces.bind(undefined, config.interfaces);
}

get [Symbol.toStringTag]() {
Expand Down Expand Up @@ -1164,7 +1159,7 @@ export class GraphQLUnionType {
this.astNode = config.astNode;
this.extensionASTNodes = config.extensionASTNodes ?? [];

this._types = defineTypes.bind(undefined, config);
this._types = defineTypes.bind(undefined, config.types);
}

get [Symbol.toStringTag]() {
Expand Down Expand Up @@ -1200,9 +1195,9 @@ export class GraphQLUnionType {
}

function defineTypes(
config: Readonly<GraphQLUnionTypeConfig<unknown, unknown>>,
types: ThunkReadonlyArray<GraphQLObjectType>,
): ReadonlyArray<GraphQLObjectType> {
return resolveReadonlyArrayThunk(config.types);
return resolveReadonlyArrayThunk(types);
}

export interface GraphQLUnionTypeConfig<TSource, TContext> {
Expand Down Expand Up @@ -1503,7 +1498,7 @@ export class GraphQLInputObjectType {
this.astNode = config.astNode;
this.extensionASTNodes = config.extensionASTNodes ?? [];

this._fields = defineInputFieldMap.bind(undefined, config);
this._fields = defineInputFieldMap.bind(undefined, config.fields);
}

get [Symbol.toStringTag]() {
Expand Down Expand Up @@ -1547,9 +1542,9 @@ export class GraphQLInputObjectType {
}

function defineInputFieldMap(
config: Readonly<GraphQLInputObjectTypeConfig>,
fields: ThunkObjMap<GraphQLInputFieldConfig>,
): GraphQLInputFieldMap {
const fieldMap = resolveObjMapThunk(config.fields);
const fieldMap = resolveObjMapThunk(fields);
return mapValue(fieldMap, (fieldConfig, fieldName) => ({
name: assertName(fieldName),
description: fieldConfig.description,
Expand Down

0 comments on commit ea10c7b

Please sign in to comment.