@@ -319,25 +319,35 @@ export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
319
319
* });
320
320
*
321
321
*/
322
- export class GraphQLObjectType {
322
+ export class GraphQLObjectType <
323
+ TSource = any ,
324
+ TContext = any ,
325
+ TConfig extends GraphQLObjectTypeConfig < TSource , TContext > = any ,
326
+ > {
323
327
name : string ;
324
328
description : Maybe < string > ;
325
329
astNode : Maybe < ObjectTypeDefinitionNode > ;
326
330
extensionASTNodes : Maybe < ReadonlyArray < ObjectTypeExtensionNode > > ;
327
331
isTypeOf : Maybe < GraphQLIsTypeOfFn < any , any > > ;
328
332
329
- constructor ( config : GraphQLObjectTypeConfig < any , any > ) ;
330
- getFields ( ) : GraphQLFieldMap < any , any > ;
333
+ constructor ( config : TConfig & GraphQLObjectTypeConfig < TSource , TContext , Unthunk < TConfig [ 'fields' ] > > ) ;
334
+ getFields ( ) : GraphQLFieldMap < TSource , TContext > ;
331
335
getInterfaces ( ) : GraphQLInterfaceType [ ] ;
332
336
toString ( ) : string ;
333
337
toJSON ( ) : string ;
334
338
inspect ( ) : string ;
335
339
}
336
340
337
- export interface GraphQLObjectTypeConfig < TSource , TContext > {
341
+ type Unthunk < T > = T extends ( ) => infer R ? R : T
342
+
343
+ export interface GraphQLObjectTypeConfig <
344
+ TSource ,
345
+ TContext ,
346
+ TFields extends GraphQLFieldConfigMap < TSource , TContext > = any
347
+ > {
338
348
name : string ;
339
349
interfaces ?: Thunk < Maybe < GraphQLInterfaceType [ ] > > ;
340
- fields : Thunk < GraphQLFieldConfigMap < TSource , TContext > > ;
350
+ fields : Thunk < GraphQLFieldConfigMapFromConfig < TSource , TContext , TFields > > ;
341
351
isTypeOf ?: Maybe < GraphQLIsTypeOfFn < TSource , TContext > > ;
342
352
description ?: Maybe < string > ;
343
353
astNode ?: Maybe < ObjectTypeDefinitionNode > ;
@@ -356,12 +366,12 @@ export type GraphQLIsTypeOfFn<TSource, TContext> = (
356
366
info : GraphQLResolveInfo
357
367
) => MaybePromise < boolean > ;
358
368
359
- export type GraphQLFieldResolver < TSource , TContext , TArgs = { [ argName : string ] : any } > = (
369
+ export type GraphQLFieldResolver < TSource , TContext , TArgs = { [ argName : string ] : any } , TResult = any > = (
360
370
source : TSource ,
361
371
args : TArgs ,
362
372
context : TContext ,
363
373
info : GraphQLResolveInfo
364
- ) => any ;
374
+ ) => TResult ;
365
375
366
376
export interface GraphQLResolveInfo {
367
377
readonly fieldName : string ;
@@ -381,10 +391,14 @@ export type ResponsePath = {
381
391
readonly key : string | number ;
382
392
} ;
383
393
384
- export interface GraphQLFieldConfig < TSource , TContext , TArgs = { [ argName : string ] : any } > {
385
- type : GraphQLOutputType ;
394
+ export type ExtractPrimitiveFromGraphQL < T > =
395
+ T extends GraphQLScalarType < infer R > ? R :
396
+ any
397
+
398
+ export interface GraphQLFieldConfig < TSource , TContext , TArgs = { [ argName : string ] : any } , TType extends GraphQLOutputType = GraphQLOutputType > {
399
+ type : TType ;
386
400
args ?: GraphQLFieldConfigArgumentMap ;
387
- resolve ?: GraphQLFieldResolver < TSource , TContext , TArgs > ;
401
+ resolve ?: GraphQLFieldResolver < TSource , TContext , TArgs , ExtractPrimitiveFromGraphQL < TType > > ;
388
402
subscribe ?: GraphQLFieldResolver < TSource , TContext , TArgs > ;
389
403
deprecationReason ?: Maybe < string > ;
390
404
description ?: Maybe < string > ;
@@ -400,8 +414,19 @@ export interface GraphQLArgumentConfig {
400
414
astNode ?: Maybe < InputValueDefinitionNode > ;
401
415
}
402
416
403
- export type GraphQLFieldConfigMap < TSource , TContext > = {
404
- [ key : string ] : GraphQLFieldConfig < TSource , TContext > ;
417
+ export type GraphQLFieldConfigMap <
418
+ TSource ,
419
+ TContext ,
420
+ > = {
421
+ [ name : string ] : GraphQLFieldConfig < TSource , TContext > ;
422
+ } ;
423
+
424
+ export type GraphQLFieldConfigMapFromConfig <
425
+ TSource ,
426
+ TContext ,
427
+ TFields extends GraphQLFieldConfigMap < TSource , TContext > = any ,
428
+ > = {
429
+ [ K in keyof TFields ] : GraphQLFieldConfig < TSource , TContext , any , TFields [ K ] [ 'type' ] > ;
405
430
} ;
406
431
407
432
export interface GraphQLField < TSource , TContext , TArgs = { [ key : string ] : any } > {
0 commit comments