@@ -12,14 +12,14 @@ import type {
1212 GraphQLFieldConfigMap ,
1313 GraphQLInputField ,
1414 GraphQLNamedType ,
15+ GraphQLOutputType ,
1516 GraphQLType ,
1617} from './definition' ;
1718import {
1819 GraphQLEnumType ,
1920 GraphQLList ,
2021 GraphQLNonNull ,
2122 GraphQLObjectType ,
22- GraphQLSemanticNonNull ,
2323 isAbstractType ,
2424 isEnumType ,
2525 isInputObjectType ,
@@ -206,40 +206,6 @@ export const __DirectiveLocation: GraphQLEnumType = new GraphQLEnumType({
206206 } ,
207207} ) ;
208208
209- // TODO: rename enum and options
210- enum TypeNullability {
211- AUTO = 'AUTO' ,
212- TRADITIONAL = 'TRADITIONAL' ,
213- SEMANTIC = 'SEMANTIC' ,
214- FULL = 'FULL' ,
215- }
216-
217- // TODO: rename
218- export const __TypeNullability : GraphQLEnumType = new GraphQLEnumType ( {
219- name : '__TypeNullability' ,
220- description : 'TODO' ,
221- values : {
222- AUTO : {
223- value : TypeNullability . AUTO ,
224- description :
225- 'Determines nullability mode based on errorPropagation mode.' ,
226- } ,
227- TRADITIONAL : {
228- value : TypeNullability . TRADITIONAL ,
229- description : 'Turn semantic-non-null types into nullable types.' ,
230- } ,
231- SEMANTIC : {
232- value : TypeNullability . SEMANTIC ,
233- description : 'Turn non-null types into semantic-non-null types.' ,
234- } ,
235- FULL : {
236- value : TypeNullability . FULL ,
237- description :
238- 'Render the true nullability in the schema; be prepared for new types of nullability in future!' ,
239- } ,
240- } ,
241- } ) ;
242-
243209export const __Type : GraphQLObjectType = new GraphQLObjectType ( {
244210 name : '__Type' ,
245211 description :
@@ -406,22 +372,17 @@ export const __Field: GraphQLObjectType = new GraphQLObjectType({
406372 type : {
407373 type : new GraphQLNonNull ( __Type ) ,
408374 args : {
409- nullability : {
410- type : new GraphQLNonNull ( __TypeNullability ) ,
411- defaultValue : TypeNullability . AUTO ,
375+ includeSemanticNonNull : {
376+ type : new GraphQLNonNull ( GraphQLBoolean ) ,
377+ defaultValue : false ,
412378 } ,
413379 } ,
414- resolve : ( field , { nullability } , _context , info ) => {
415- if ( nullability === TypeNullability . FULL ) {
380+ resolve : ( field , { includeSemanticNonNull } , _context ) => {
381+ if ( includeSemanticNonNull ) {
416382 return field . type ;
417383 }
418- const mode =
419- nullability === TypeNullability . AUTO
420- ? info . errorPropagation
421- ? TypeNullability . TRADITIONAL
422- : TypeNullability . SEMANTIC
423- : nullability ;
424- return convertOutputTypeToNullabilityMode ( field . type , mode ) ;
384+ // TODO: memoize
385+ return stripSemanticNonNullTypes ( field . type ) ;
425386 } ,
426387 } ,
427388 isDeprecated : {
@@ -436,32 +397,21 @@ export const __Field: GraphQLObjectType = new GraphQLObjectType({
436397} ) ;
437398
438399// TODO: move this elsewhere, rename, memoize
439- function convertOutputTypeToNullabilityMode (
440- type : GraphQLType ,
441- mode : TypeNullability . TRADITIONAL | TypeNullability . SEMANTIC ,
442- ) : GraphQLType {
443- if ( mode === TypeNullability . TRADITIONAL ) {
444- if ( isNonNullType ( type ) ) {
445- return new GraphQLNonNull (
446- convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
447- ) ;
448- } else if ( isSemanticNonNullType ( type ) ) {
449- return convertOutputTypeToNullabilityMode ( type . ofType , mode ) ;
450- } else if ( isListType ( type ) ) {
451- return new GraphQLList (
452- convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
453- ) ;
400+ function stripSemanticNonNullTypes ( type : GraphQLOutputType ) : GraphQLOutputType {
401+ if ( isNonNullType ( type ) ) {
402+ const convertedInner = stripSemanticNonNullTypes ( type . ofType ) ;
403+ if ( convertedInner === type . ofType ) {
404+ return type ; // No change needed
454405 }
455- return type ;
456- }
457- if ( isNonNullType ( type ) || isSemanticNonNullType ( type ) ) {
458- return new GraphQLSemanticNonNull (
459- convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
460- ) ;
406+ return new GraphQLNonNull ( convertedInner ) ;
461407 } else if ( isListType ( type ) ) {
462- return new GraphQLList (
463- convertOutputTypeToNullabilityMode ( type . ofType , mode ) ,
464- ) ;
408+ const convertedInner = stripSemanticNonNullTypes ( type . ofType ) ;
409+ if ( convertedInner === type . ofType ) {
410+ return type ; // No change needed
411+ }
412+ return new GraphQLList ( convertedInner ) ;
413+ } else if ( isSemanticNonNullType ( type ) ) {
414+ return stripSemanticNonNullTypes ( type . ofType ) ;
465415 }
466416 return type ;
467417}
@@ -646,7 +596,6 @@ export const introspectionTypes: ReadonlyArray<GraphQLNamedType> =
646596 __Schema ,
647597 __Directive ,
648598 __DirectiveLocation ,
649- __TypeNullability ,
650599 __Type ,
651600 __Field ,
652601 __InputValue ,
0 commit comments