@@ -37,8 +37,9 @@ import {
3737 isWrapperType ,
3838 possibleRuntimeTypes ,
3939 isIntType ,
40+ Type ,
4041} from "./definitions" ;
41- import { assert , MultiMap , printHumanReadableList , OrderedMap , mapValues , assertUnreachable , isDefined } from "./utils" ;
42+ import { assert , MultiMap , printHumanReadableList , OrderedMap , mapValues , assertUnreachable } from "./utils" ;
4243import { SDLValidationRule } from "graphql/validation/ValidationContext" ;
4344import { specifiedSDLRules } from "graphql/validation/specifiedRules" ;
4445import {
@@ -1097,14 +1098,18 @@ function validateAssumedSizeNotNegative(
10971098 // We omit this check to keep the validations to those that will otherwise cause runtime failures.
10981099 //
10991100 // With all that said, assumed size should not be negative.
1100- if ( isDefined ( assumedSize ) && assumedSize < 0 ) {
1101+ if ( assumedSize !== undefined && assumedSize !== null && assumedSize < 0 ) {
11011102 errorCollector . push ( ERRORS . LIST_SIZE_INVALID_ASSUMED_SIZE . err (
11021103 `Assumed size of "${ parent . coordinate } " cannot be negative` ,
11031104 { nodes : sourceASTs ( application , parent ) } ,
11041105 ) ) ;
11051106 }
11061107}
11071108
1109+ function isNonNullIntType ( ty : Type ) : boolean {
1110+ return isNonNullType ( ty ) && isIntType ( ty . ofType )
1111+ }
1112+
11081113function validateSlicingArgumentsAreValidIntegers (
11091114 application : Directive < SchemaElement < any , any > , ListSizeDirectiveArguments > ,
11101115 parent : FieldDefinition < CompositeType > ,
@@ -1120,7 +1125,7 @@ function validateSlicingArgumentsAreValidIntegers(
11201125 `Slicing argument "${ slicingArgumentName } " is not an argument of "${ parent . coordinate } "` ,
11211126 { nodes : sourceASTs ( application , parent ) }
11221127 ) ) ;
1123- } else if ( ! isIntType ( slicingArgument . type ) && ! ( isNonNullType ( slicingArgument . type ) && isIntType ( slicingArgument . type . baseType ( ) ) ) ) {
1128+ } else if ( ! isIntType ( slicingArgument . type ) && ! isNonNullIntType ( slicingArgument . type ) ) {
11241129 // Slicing arguments must be Int or Int!
11251130 errorCollector . push ( ERRORS . LIST_SIZE_INVALID_SLICING_ARGUMENT . err (
11261131 `Slicing argument "${ slicingArgument . coordinate } " must be Int or Int!` ,
@@ -1130,6 +1135,10 @@ function validateSlicingArgumentsAreValidIntegers(
11301135 }
11311136}
11321137
1138+ function isNonNullListType ( ty : Type ) : boolean {
1139+ return isNonNullType ( ty ) && isListType ( ty . ofType )
1140+ }
1141+
11331142function validateSizedFieldsAreValidLists (
11341143 application : Directive < SchemaElement < any , any > , ListSizeDirectiveArguments > ,
11351144 parent : FieldDefinition < CompositeType > ,
@@ -1141,7 +1150,7 @@ function validateSizedFieldsAreValidLists(
11411150 if ( ! parent . type || ! isCompositeType ( parent . type ) ) {
11421151 // The output type must have fields
11431152 errorCollector . push ( ERRORS . LIST_SIZE_INVALID_SIZED_FIELD . err (
1144- `Sized fields cannot be used because "${ parent . type } " is not an object type` ,
1153+ `Sized fields cannot be used because "${ parent . type } " is not a composite type` ,
11451154 { nodes : sourceASTs ( application , parent ) }
11461155 ) ) ;
11471156 } else {
@@ -1153,7 +1162,7 @@ function validateSizedFieldsAreValidLists(
11531162 `Sized field "${ sizedFieldName } " is not a field on type "${ parent . type . coordinate } "` ,
11541163 { nodes : sourceASTs ( application , parent ) }
11551164 ) ) ;
1156- } else if ( ! sizedField . type || ! isListType ( sizedField . type ) ) {
1165+ } else if ( ! sizedField . type || ! ( isListType ( sizedField . type ) || isNonNullListType ( sizedField . type ) ) ) {
11571166 // Sized fields must be lists
11581167 errorCollector . push ( ERRORS . LIST_SIZE_APPLIED_TO_NON_LIST . err (
11591168 `Sized field "${ sizedField . coordinate } " is not a list` ,
0 commit comments