@@ -206,36 +206,23 @@ export const __DirectiveLocation: GraphQLEnumType = new GraphQLEnumType({
206
206
} ,
207
207
} ) ;
208
208
209
- // TODO: rename enum and options
210
209
enum TypeNullability {
211
- AUTO = 'AUTO' ,
212
210
TRADITIONAL = 'TRADITIONAL' ,
213
- SEMANTIC = 'SEMANTIC' ,
214
211
FULL = 'FULL' ,
215
212
}
216
213
217
- // TODO: rename
218
214
export const __TypeNullability : GraphQLEnumType = new GraphQLEnumType ( {
219
215
name : '__TypeNullability' ,
220
- description : 'TODO' ,
216
+ description :
217
+ 'This represents the type of nullability we want to return as part of the introspection.' ,
221
218
values : {
222
- AUTO : {
223
- value : TypeNullability . AUTO ,
224
- description :
225
- 'Determines nullability mode based on errorPropagation mode.' ,
226
- } ,
227
219
TRADITIONAL : {
228
220
value : TypeNullability . TRADITIONAL ,
229
221
description : 'Turn semantic-non-null types into nullable types.' ,
230
222
} ,
231
- SEMANTIC : {
232
- value : TypeNullability . SEMANTIC ,
233
- description : 'Turn non-null types into semantic-non-null types.' ,
234
- } ,
235
223
FULL : {
236
224
value : TypeNullability . FULL ,
237
- description :
238
- 'Render the true nullability in the schema; be prepared for new types of nullability in future!' ,
225
+ description : 'Allow for returning semantic-non-null types.' ,
239
226
} ,
240
227
} ,
241
228
} ) ;
@@ -408,22 +395,11 @@ export const __Field: GraphQLObjectType = new GraphQLObjectType({
408
395
args : {
409
396
nullability : {
410
397
type : new GraphQLNonNull ( __TypeNullability ) ,
411
- defaultValue : TypeNullability . AUTO ,
398
+ defaultValue : TypeNullability . TRADITIONAL ,
412
399
} ,
413
400
} ,
414
- resolve : ( field , { nullability } , _context , info ) => {
415
- if ( nullability === TypeNullability . FULL ) {
416
- return field . type ;
417
- }
418
-
419
- const mode =
420
- nullability === TypeNullability . AUTO
421
- ? info . errorPropagation
422
- ? TypeNullability . TRADITIONAL
423
- : TypeNullability . SEMANTIC
424
- : nullability ;
425
- return convertOutputTypeToNullabilityMode ( field . type , mode ) ;
426
- } ,
401
+ resolve : ( field , { nullability } , _context ) =>
402
+ convertOutputTypeToNullabilityMode ( field . type , nullability ) ,
427
403
} ,
428
404
isDeprecated : {
429
405
type : new GraphQLNonNull ( GraphQLBoolean ) ,
@@ -436,10 +412,9 @@ export const __Field: GraphQLObjectType = new GraphQLObjectType({
436
412
} as GraphQLFieldConfigMap < GraphQLField < unknown , unknown > , unknown > ) ,
437
413
} ) ;
438
414
439
- // TODO: move this elsewhere, rename, memoize
440
415
function convertOutputTypeToNullabilityMode (
441
416
type : GraphQLType ,
442
- mode : TypeNullability . TRADITIONAL | TypeNullability . SEMANTIC ,
417
+ mode : TypeNullability ,
443
418
) : GraphQLType {
444
419
if ( mode === TypeNullability . TRADITIONAL ) {
445
420
if ( isNonNullType ( type ) ) {
@@ -455,7 +430,12 @@ function convertOutputTypeToNullabilityMode(
455
430
}
456
431
return type ;
457
432
}
458
- if ( isNonNullType ( type ) || isSemanticNonNullType ( type ) ) {
433
+
434
+ if ( isNonNullType ( type ) ) {
435
+ return new GraphQLNonNull (
436
+ convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
437
+ ) ;
438
+ } else if ( isSemanticNonNullType ( type ) ) {
459
439
return new GraphQLSemanticNonNull (
460
440
convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
461
441
) ;
@@ -464,6 +444,7 @@ function convertOutputTypeToNullabilityMode(
464
444
convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
465
445
) ;
466
446
}
447
+
467
448
return type ;
468
449
}
469
450
0 commit comments