@@ -38,16 +38,32 @@ import type { GraphQLSchema } from '../type/schema';
3838
3939import { astFromValue } from './astFromValue' ;
4040
41- export function printSchema ( schema : GraphQLSchema ) : string {
41+ interface PrintOptions {
42+ usingSemanticNullability ?: boolean ;
43+ }
44+
45+ export function printSchema (
46+ schema : GraphQLSchema ,
47+ options : PrintOptions = { } ,
48+ ) : string {
4249 return printFilteredSchema (
4350 schema ,
4451 ( n ) => ! isSpecifiedDirective ( n ) ,
4552 isDefinedType ,
53+ options ,
4654 ) ;
4755}
4856
49- export function printIntrospectionSchema ( schema : GraphQLSchema ) : string {
50- return printFilteredSchema ( schema , isSpecifiedDirective , isIntrospectionType ) ;
57+ export function printIntrospectionSchema (
58+ schema : GraphQLSchema ,
59+ options : PrintOptions = { } ,
60+ ) : string {
61+ return printFilteredSchema (
62+ schema ,
63+ isSpecifiedDirective ,
64+ isIntrospectionType ,
65+ options ,
66+ ) ;
5167}
5268
5369function isDefinedType ( type : GraphQLNamedType ) : boolean {
@@ -58,13 +74,16 @@ function printFilteredSchema(
5874 schema : GraphQLSchema ,
5975 directiveFilter : ( type : GraphQLDirective ) => boolean ,
6076 typeFilter : ( type : GraphQLNamedType ) => boolean ,
77+ options : PrintOptions ,
6178) : string {
6279 const directives = schema . getDirectives ( ) . filter ( directiveFilter ) ;
6380 const types = Object . values ( schema . getTypeMap ( ) ) . filter ( typeFilter ) ;
6481
65- const usingSemanticNullability = schema . usingSemanticNullability ;
82+ const usingSemanticNullability =
83+ options . usingSemanticNullability ?? schema . usingSemanticNullability ;
6684
6785 return [
86+ usingSemanticNullability ? '@SemanticNullability' : undefined ,
6887 printSchemaDefinition ( schema ) ,
6988 ...directives . map ( ( directive ) => printDirective ( directive ) ) ,
7089 ...types . map ( ( type ) => printType ( type , usingSemanticNullability ) ) ,
0 commit comments