@@ -34,6 +34,10 @@ interface WrapFieldsTransformationContext {
3434 paths : Record < string , { pathToField : Array < string > ; alias : string } > ;
3535}
3636
37+ interface WrapFieldsConfig {
38+ isNullable ?: boolean ;
39+ }
40+
3741export default class WrapFields < TContext extends Record < string , any > >
3842 implements Transform < WrapFieldsTransformationContext , TContext >
3943{
@@ -43,19 +47,22 @@ export default class WrapFields<TContext extends Record<string, any>>
4347 private readonly numWraps : number ;
4448 private readonly fieldNames : Array < string > | undefined ;
4549 private readonly transformer : MapFields < TContext > ;
50+ private readonly config : WrapFieldsConfig ;
4651
4752 constructor (
4853 outerTypeName : string ,
4954 wrappingFieldNames : Array < string > ,
5055 wrappingTypeNames : Array < string > ,
5156 fieldNames ?: Array < string > ,
5257 prefix = 'gqtld' ,
58+ config : WrapFieldsConfig = { isNullable : false } ,
5359 ) {
5460 this . outerTypeName = outerTypeName ;
5561 this . wrappingFieldNames = wrappingFieldNames ;
5662 this . wrappingTypeNames = wrappingTypeNames ;
5763 this . numWraps = wrappingFieldNames . length ;
5864 this . fieldNames = fieldNames ;
65+ this . config = config ;
5966
6067 const remainingWrappingFieldNames = this . wrappingFieldNames . slice ( ) ;
6168 const outerMostWrappingFieldName = remainingWrappingFieldNames . shift ( ) ;
@@ -167,9 +174,11 @@ export default class WrapFields<TContext extends Record<string, any>>
167174 resolve = defaultMergedResolver ;
168175 }
169176
170- const wrappingType = new GraphQLNonNull (
171- newSchema . getType ( wrappingTypeName ) as GraphQLObjectType ,
172- ) ;
177+ const baseType = newSchema . getType ( wrappingTypeName ) as GraphQLObjectType ;
178+ const wrappingType = this . config . isNullable
179+ ? baseType
180+ : new GraphQLNonNull ( baseType ) ;
181+
173182 const newFieldConfig : GraphQLFieldConfig < any , any > =
174183 wrappingOperation === 'subscription'
175184 ? {
0 commit comments