Skip to content

Commit ea10c7b

Browse files
GraphQL*Type: bind only single property instead of entire context (#3876)
1 parent 74e51d7 commit ea10c7b

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/type/definition.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,8 @@ export class GraphQLObjectType<TSource = any, TContext = any> {
721721

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

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

768768
function defineInterfaces(
769-
config: Readonly<
770-
GraphQLObjectTypeConfig<any, any> | GraphQLInterfaceTypeConfig<any, any>
771-
>,
769+
interfaces: Maybe<ThunkReadonlyArray<GraphQLInterfaceType>>,
772770
): ReadonlyArray<GraphQLInterfaceType> {
773-
return resolveReadonlyArrayThunk(config.interfaces ?? []);
771+
return resolveReadonlyArrayThunk(interfaces ?? []);
774772
}
775773

776774
function defineFieldMap<TSource, TContext>(
777-
config: Readonly<
778-
| GraphQLObjectTypeConfig<TSource, TContext>
779-
| GraphQLInterfaceTypeConfig<TSource, TContext>
780-
>,
775+
fields: ThunkObjMap<GraphQLFieldConfig<TSource, TContext>>,
781776
): GraphQLFieldMap<TSource, TContext> {
782-
const fieldMap = resolveObjMapThunk(config.fields);
777+
const fieldMap = resolveObjMapThunk(fields);
783778

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

800795
export function defineArguments(
801-
config: GraphQLFieldConfigArgumentMap,
796+
args: GraphQLFieldConfigArgumentMap,
802797
): ReadonlyArray<GraphQLArgument> {
803-
return Object.entries(config).map(([argName, argConfig]) => ({
798+
return Object.entries(args).map(([argName, argConfig]) => ({
804799
name: assertName(argName),
805800
description: argConfig.description,
806801
type: argConfig.type,
@@ -1041,8 +1036,8 @@ export class GraphQLInterfaceType {
10411036
this.astNode = config.astNode;
10421037
this.extensionASTNodes = config.extensionASTNodes ?? [];
10431038

1044-
this._fields = defineFieldMap.bind(undefined, config);
1045-
this._interfaces = defineInterfaces.bind(undefined, config);
1039+
this._fields = defineFieldMap.bind(undefined, config.fields);
1040+
this._interfaces = defineInterfaces.bind(undefined, config.interfaces);
10461041
}
10471042

10481043
get [Symbol.toStringTag]() {
@@ -1164,7 +1159,7 @@ export class GraphQLUnionType {
11641159
this.astNode = config.astNode;
11651160
this.extensionASTNodes = config.extensionASTNodes ?? [];
11661161

1167-
this._types = defineTypes.bind(undefined, config);
1162+
this._types = defineTypes.bind(undefined, config.types);
11681163
}
11691164

11701165
get [Symbol.toStringTag]() {
@@ -1200,9 +1195,9 @@ export class GraphQLUnionType {
12001195
}
12011196

12021197
function defineTypes(
1203-
config: Readonly<GraphQLUnionTypeConfig<unknown, unknown>>,
1198+
types: ThunkReadonlyArray<GraphQLObjectType>,
12041199
): ReadonlyArray<GraphQLObjectType> {
1205-
return resolveReadonlyArrayThunk(config.types);
1200+
return resolveReadonlyArrayThunk(types);
12061201
}
12071202

12081203
export interface GraphQLUnionTypeConfig<TSource, TContext> {
@@ -1503,7 +1498,7 @@ export class GraphQLInputObjectType {
15031498
this.astNode = config.astNode;
15041499
this.extensionASTNodes = config.extensionASTNodes ?? [];
15051500

1506-
this._fields = defineInputFieldMap.bind(undefined, config);
1501+
this._fields = defineInputFieldMap.bind(undefined, config.fields);
15071502
}
15081503

15091504
get [Symbol.toStringTag]() {
@@ -1547,9 +1542,9 @@ export class GraphQLInputObjectType {
15471542
}
15481543

15491544
function defineInputFieldMap(
1550-
config: Readonly<GraphQLInputObjectTypeConfig>,
1545+
fields: ThunkObjMap<GraphQLInputFieldConfig>,
15511546
): GraphQLInputFieldMap {
1552-
const fieldMap = resolveObjMapThunk(config.fields);
1547+
const fieldMap = resolveObjMapThunk(fields);
15531548
return mapValue(fieldMap, (fieldConfig, fieldName) => ({
15541549
name: assertName(fieldName),
15551550
description: fieldConfig.description,

0 commit comments

Comments
 (0)