@@ -34,6 +34,10 @@ interface WrapFieldsTransformationContext {
34
34
paths : Record < string , { pathToField : Array < string > ; alias : string } > ;
35
35
}
36
36
37
+ interface WrapFieldsConfig {
38
+ isNullable ?: boolean ;
39
+ }
40
+
37
41
export default class WrapFields < TContext extends Record < string , any > >
38
42
implements Transform < WrapFieldsTransformationContext , TContext >
39
43
{
@@ -43,19 +47,22 @@ export default class WrapFields<TContext extends Record<string, any>>
43
47
private readonly numWraps : number ;
44
48
private readonly fieldNames : Array < string > | undefined ;
45
49
private readonly transformer : MapFields < TContext > ;
50
+ private readonly config : WrapFieldsConfig ;
46
51
47
52
constructor (
48
53
outerTypeName : string ,
49
54
wrappingFieldNames : Array < string > ,
50
55
wrappingTypeNames : Array < string > ,
51
56
fieldNames ?: Array < string > ,
52
57
prefix = 'gqtld' ,
58
+ config : WrapFieldsConfig = { isNullable : false } ,
53
59
) {
54
60
this . outerTypeName = outerTypeName ;
55
61
this . wrappingFieldNames = wrappingFieldNames ;
56
62
this . wrappingTypeNames = wrappingTypeNames ;
57
63
this . numWraps = wrappingFieldNames . length ;
58
64
this . fieldNames = fieldNames ;
65
+ this . config = config ;
59
66
60
67
const remainingWrappingFieldNames = this . wrappingFieldNames . slice ( ) ;
61
68
const outerMostWrappingFieldName = remainingWrappingFieldNames . shift ( ) ;
@@ -167,9 +174,11 @@ export default class WrapFields<TContext extends Record<string, any>>
167
174
resolve = defaultMergedResolver ;
168
175
}
169
176
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
+
173
182
const newFieldConfig : GraphQLFieldConfig < any , any > =
174
183
wrappingOperation === 'subscription'
175
184
? {
0 commit comments