@@ -50,6 +50,13 @@ export async function main(toStrict = false) {
50
50
throw new Error ( "Invalid schema" ) ;
51
51
}
52
52
53
+ const derivedSchema = convertSchema ( schema , toStrict ) ;
54
+
55
+ const newSdl = printSchema ( derivedSchema ) ;
56
+ await writeFile ( output , newSdl + "\n" ) ;
57
+ }
58
+
59
+ function convertSchema ( schema : GraphQLSchema , toStrict : boolean ) {
53
60
const config = schema . toConfig ( ) ;
54
61
const convertType = makeConvertType ( toStrict ) ;
55
62
const derivedSchema = new GraphQLSchema ( {
@@ -62,10 +69,15 @@ export async function main(toStrict = false) {
62
69
. map ( ( t ) => convertType ( t ) ) ,
63
70
directives : config . directives . filter ( ( d ) => d . name !== "semanticNonNull" ) ,
64
71
} ) ;
72
+ return derivedSchema ;
73
+ }
65
74
66
- const newSdl = printSchema ( derivedSchema ) ;
75
+ export function semanticToNullable ( schema : GraphQLSchema ) {
76
+ return convertSchema ( schema , false ) ;
77
+ }
67
78
68
- await writeFile ( output , newSdl + "\n" ) ;
79
+ export function semanticToStrict ( schema : GraphQLSchema ) {
80
+ return convertSchema ( schema , true ) ;
69
81
}
70
82
71
83
function makeConvertType ( toStrict : boolean ) {
@@ -75,7 +87,7 @@ function makeConvertType(toStrict: boolean) {
75
87
return ( ) => {
76
88
return Object . fromEntries (
77
89
Object . entries ( fields ) . map ( ( [ fieldName , inSpec ] ) => {
78
- const spec = applySemanticNonNullDirective ( inSpec ) ;
90
+ const spec = applySemanticNonNullDirectiveToFieldConfig ( inSpec ) ;
79
91
return [
80
92
fieldName ,
81
93
{
@@ -174,7 +186,7 @@ function makeConvertType(toStrict: boolean) {
174
186
*
175
187
* @see {@url https://www.apollographql.com/docs/kotlin/advanced/nullability/#semanticnonnull }
176
188
*/
177
- function applySemanticNonNullDirective (
189
+ export function applySemanticNonNullDirectiveToFieldConfig (
178
190
spec : GraphQLFieldConfig < any , any , any > ,
179
191
) : GraphQLFieldConfig < any , any , any > {
180
192
const directive = spec . astNode ?. directives ?. find (
0 commit comments