@@ -4,7 +4,6 @@ import type { Model, Document } from 'mongoose';
44import { convertModelToGraphQL } from './fieldsConverter' ;
55import { allResolvers } from './resolvers' ;
66import MongoID from './types/MongoID' ;
7- import { ArgsMap } from './resolvers/helpers' ;
87import {
98 prepareFields ,
109 createInputType ,
@@ -27,13 +26,18 @@ export type ComposeMongooseOpts<TContext> = {
2726} ;
2827
2928export type GenerateResolverType < TDoc extends Document , TContext = any > = {
30- // get all available resolver generators, then leave only 3rd arg – opts
29+ // Get all available resolver generators, then leave only 3rd arg – opts
3130 // because first two args will be attached via bind() method at runtime:
3231 // count = count.bind(undefined, model, tc);
33- // TODO: explain infer
3432 [ resolver in keyof typeof allResolvers ] : < TSource = any > (
3533 opts ?: Parameters < typeof allResolvers [ resolver ] > [ 2 ]
36- ) => typeof allResolvers [ resolver ] extends ( ...args : any ) => Resolver < any , any , infer TArgs , any >
34+ ) => // Also we should patch generics of the returned Resolver
35+ // attach TContext TDoc from the code which will bind at runtime
36+ // and allow user to attach TSource via generic at call
37+ // For this case we are using `extends infer` construction
38+ // it helps to extract any Generic from existed method
39+ // and then construct new combined return type
40+ typeof allResolvers [ resolver ] extends ( ...args : any ) => Resolver < any , any , infer TArgs , any >
3741 ? Resolver < TSource , TContext , TArgs , TDoc >
3842 : any ;
3943} ;
0 commit comments