@@ -23,7 +23,8 @@ import * as graphql from "graphql";
23
23
type Maybe < T > = null | undefined | T ;
24
24
25
25
// If GraphQL doesn't have this helper function, then it doesn't natively support GraphQLSemanticNonNull
26
- const isSemanticNonNullType = graphql . isSemanticNonNullType ?? ( ( ) => false ) ;
26
+ const isSemanticNonNullType =
27
+ ( graphql as any ) . isSemanticNonNullType ?? ( ( ) => false ) ;
27
28
28
29
function convertSchema ( schema : GraphQLSchema , toStrict : boolean ) {
29
30
const config = schema . toConfig ( ) ;
@@ -102,7 +103,9 @@ function makeConvertType(toStrict: boolean) {
102
103
return type ;
103
104
}
104
105
if ( isSemanticNonNullType ( type ) ) {
105
- const unwrapped = convertType ( type . ofType as GraphQLNullableType ) ;
106
+ const unwrapped = convertType (
107
+ ( type as any ) . ofType as GraphQLNullableType ,
108
+ ) ;
106
109
// Here's where we do our thing!
107
110
if ( toStrict ) {
108
111
return new GraphQLNonNull ( unwrapped ) ;
@@ -180,16 +183,6 @@ export function convertFieldConfig(
180
183
) ,
181
184
} ;
182
185
183
- if ( ! toStrict ) {
184
- // If we're not converting to strict, we can simply strip this directive
185
- return {
186
- ...spec ,
187
- astNode : filteredAstNode ,
188
- } ;
189
- }
190
-
191
- // Otherwise, convert semantic non-null positions to strict non-null
192
-
193
186
const levelsArg = directive . arguments ?. find ( ( a ) => a . name . value === "levels" ) ;
194
187
const levels =
195
188
levelsArg ?. value ?. kind === Kind . LIST
@@ -202,25 +195,27 @@ export function convertFieldConfig(
202
195
// Strip semantic-non-null types; this should never happen but if someone
203
196
// uses both semantic-non-null and the `@semanticNonNull` directive, we
204
197
// want the directive to win (I guess?)
205
- return recurse ( type . ofType , level ) ;
198
+ return recurse (
199
+ ( type as any ) . ofType as GraphQLNullableType & GraphQLOutputType ,
200
+ level ,
201
+ ) ;
206
202
} else if ( isNonNullType ( type ) ) {
207
203
const inner = recurse ( type . ofType , level ) ;
208
- if ( levels . includes ( level ) ) {
209
- // Semantic non-null from `inner` replaces our GraphQLNonNull wrapper
204
+ if ( isNonNullType ( inner ) ) {
210
205
return inner ;
211
206
} else {
212
- // Keep non-null wrapper; no semantic-non-null was added to `inner`
207
+ // Carry the non-null through no matter what semantic says
213
208
return new GraphQLNonNull ( inner ) ;
214
209
}
215
210
} else if ( isListType ( type ) ) {
216
211
const inner = new GraphQLList ( recurse ( type . ofType , level + 1 ) ) ;
217
- if ( levels . includes ( level ) ) {
212
+ if ( toStrict && levels . includes ( level ) ) {
218
213
return new GraphQLNonNull ( inner ) ;
219
214
} else {
220
215
return inner ;
221
216
}
222
217
} else {
223
- if ( levels . includes ( level ) ) {
218
+ if ( toStrict && levels . includes ( level ) ) {
224
219
return new GraphQLNonNull ( type ) ;
225
220
} else {
226
221
return type ;
0 commit comments