@@ -6,14 +6,15 @@ import {
6
6
GraphQLString ,
7
7
GraphQLBoolean ,
8
8
getNamedType ,
9
+ resolveObjMapThunk ,
9
10
} from 'graphql' ;
10
11
11
12
import type {
12
13
GraphQLNamedOutputType ,
13
14
GraphQLFieldConfigArgumentMap ,
14
- GraphQLFieldConfigMap ,
15
+ GraphQLFieldConfig ,
15
16
GraphQLFieldResolver ,
16
- Thunk ,
17
+ ThunkObjMap ,
17
18
} from 'graphql' ;
18
19
19
20
/**
@@ -79,22 +80,15 @@ export interface ConnectionConfig {
79
80
nodeType : GraphQLNamedOutputType | GraphQLNonNull < GraphQLNamedOutputType > ;
80
81
resolveNode ?: GraphQLFieldResolver < any , any > ;
81
82
resolveCursor ?: GraphQLFieldResolver < any , any > ;
82
- edgeFields ?: Thunk < GraphQLFieldConfigMap < any , any > > ;
83
- connectionFields ?: Thunk < GraphQLFieldConfigMap < any , any > > ;
83
+ edgeFields ?: ThunkObjMap < GraphQLFieldConfig < any , any > > ;
84
+ connectionFields ?: ThunkObjMap < GraphQLFieldConfig < any , any > > ;
84
85
}
85
86
86
87
export interface GraphQLConnectionDefinitions {
87
88
edgeType : GraphQLObjectType ;
88
89
connectionType : GraphQLObjectType ;
89
90
}
90
91
91
- function resolveMaybeThunk < T > ( thingOrThunk : Thunk < T > ) : T {
92
- return typeof thingOrThunk === 'function'
93
- ? // @ts -expect-error - if it's a function, we assume a thunk without arguments
94
- thingOrThunk ( )
95
- : thingOrThunk ;
96
- }
97
-
98
92
/**
99
93
* Returns a GraphQLObjectType for a connection with the given name,
100
94
* and whose nodes are of the specified type.
@@ -118,7 +112,7 @@ export function connectionDefinitions(
118
112
resolve : config . resolveCursor ,
119
113
description : 'A cursor for use in pagination' ,
120
114
} ,
121
- ...resolveMaybeThunk ( config . edgeFields ?? { } ) ,
115
+ ...resolveObjMapThunk ( config . edgeFields ?? { } ) ,
122
116
} ) ,
123
117
} ) ;
124
118
@@ -134,7 +128,7 @@ export function connectionDefinitions(
134
128
type : new GraphQLList ( edgeType ) ,
135
129
description : 'A list of edges.' ,
136
130
} ,
137
- ...resolveMaybeThunk ( config . connectionFields ?? { } ) ,
131
+ ...resolveObjMapThunk ( config . connectionFields ?? { } ) ,
138
132
} ) ,
139
133
} ) ;
140
134
0 commit comments