Skip to content

Commit 3cf08e6

Browse files
printSchema: correctly print empty description (#3869)
1 parent efa97f6 commit 3cf08e6

File tree

2 files changed

+123
-6
lines changed

2 files changed

+123
-6
lines changed

src/utilities/__tests__/printSchema-test.ts

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,16 +601,133 @@ describe('Type System Printer', () => {
601601
`);
602602
});
603603

604-
it('Prints an empty description', () => {
605-
const schema = buildSingleFieldSchema({
606-
type: GraphQLString,
604+
it('Prints an empty descriptions', () => {
605+
const args = {
606+
someArg: { description: '', type: GraphQLString },
607+
anotherArg: { description: '', type: GraphQLString },
608+
};
609+
610+
const fields = {
611+
someField: { description: '', type: GraphQLString, args },
612+
anotherField: { description: '', type: GraphQLString, args },
613+
};
614+
615+
const queryType = new GraphQLObjectType({
616+
name: 'Query',
607617
description: '',
618+
fields,
619+
});
620+
621+
const scalarType = new GraphQLScalarType({
622+
name: 'SomeScalar',
623+
description: '',
624+
});
625+
626+
const interfaceType = new GraphQLInterfaceType({
627+
name: 'SomeInterface',
628+
description: '',
629+
fields,
630+
});
631+
632+
const unionType = new GraphQLUnionType({
633+
name: 'SomeUnion',
634+
description: '',
635+
types: [queryType],
636+
});
637+
638+
const enumType = new GraphQLEnumType({
639+
name: 'SomeEnum',
640+
description: '',
641+
values: {
642+
SOME_VALUE: { description: '' },
643+
ANOTHER_VALUE: { description: '' },
644+
},
645+
});
646+
647+
const someDirective = new GraphQLDirective({
648+
name: 'someDirective',
649+
description: '',
650+
args,
651+
locations: [DirectiveLocation.QUERY],
652+
});
653+
654+
const schema = new GraphQLSchema({
655+
description: '',
656+
query: queryType,
657+
types: [scalarType, interfaceType, unionType, enumType],
658+
directives: [someDirective],
608659
});
609660

610661
expectPrintedSchema(schema).to.equal(dedent`
662+
""""""
663+
schema {
664+
query: Query
665+
}
666+
667+
""""""
668+
directive @someDirective(
669+
""""""
670+
someArg: String
671+
672+
""""""
673+
anotherArg: String
674+
) on QUERY
675+
676+
""""""
677+
scalar SomeScalar
678+
679+
""""""
680+
interface SomeInterface {
681+
""""""
682+
someField(
683+
""""""
684+
someArg: String
685+
686+
""""""
687+
anotherArg: String
688+
): String
689+
690+
""""""
691+
anotherField(
692+
""""""
693+
someArg: String
694+
695+
""""""
696+
anotherArg: String
697+
): String
698+
}
699+
700+
""""""
701+
union SomeUnion = Query
702+
703+
""""""
611704
type Query {
612705
""""""
613-
singleField: String
706+
someField(
707+
""""""
708+
someArg: String
709+
710+
""""""
711+
anotherArg: String
712+
): String
713+
714+
""""""
715+
anotherField(
716+
""""""
717+
someArg: String
718+
719+
""""""
720+
anotherArg: String
721+
): String
722+
}
723+
724+
""""""
725+
enum SomeEnum {
726+
""""""
727+
SOME_VALUE
728+
729+
""""""
730+
ANOTHER_VALUE
614731
}
615732
`);
616733
});

src/utilities/printSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function printSchemaDefinition(schema: GraphQLSchema): Maybe<string> {
8282

8383
// Only print a schema definition if there is a description or if it should
8484
// not be omitted because of having default type names.
85-
if (schema.description || !hasDefaultRootOperationTypes(schema)) {
85+
if (schema.description != null || !hasDefaultRootOperationTypes(schema)) {
8686
return (
8787
printDescription(schema) +
8888
'schema {\n' +
@@ -234,7 +234,7 @@ function printArgs(
234234
}
235235

236236
// If every arg does not have a description, print them on one line.
237-
if (args.every((arg) => !arg.description)) {
237+
if (args.every((arg) => arg.description == null)) {
238238
return '(' + args.map(printInputValue).join(', ') + ')';
239239
}
240240

0 commit comments

Comments
 (0)