Skip to content

Commit aeddced

Browse files
IvanGoncharovyaacovCR
authored andcommitted
printSchema: correctly print empty description (#3869)
1 parent da551b4 commit aeddced

2 files changed

Lines changed: 123 additions & 6 deletions

File tree

src/utilities/__tests__/printSchema-test.ts

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

621-
it('Prints an empty description', () => {
622-
const schema = buildSingleFieldSchema({
623-
type: GraphQLString,
621+
it('Prints an empty descriptions', () => {
622+
const args = {
623+
someArg: { description: '', type: GraphQLString },
624+
anotherArg: { description: '', type: GraphQLString },
625+
};
626+
627+
const fields = {
628+
someField: { description: '', type: GraphQLString, args },
629+
anotherField: { description: '', type: GraphQLString, args },
630+
};
631+
632+
const queryType = new GraphQLObjectType({
633+
name: 'Query',
624634
description: '',
635+
fields,
636+
});
637+
638+
const scalarType = new GraphQLScalarType({
639+
name: 'SomeScalar',
640+
description: '',
641+
});
642+
643+
const interfaceType = new GraphQLInterfaceType({
644+
name: 'SomeInterface',
645+
description: '',
646+
fields,
647+
});
648+
649+
const unionType = new GraphQLUnionType({
650+
name: 'SomeUnion',
651+
description: '',
652+
types: [queryType],
653+
});
654+
655+
const enumType = new GraphQLEnumType({
656+
name: 'SomeEnum',
657+
description: '',
658+
values: {
659+
SOME_VALUE: { description: '' },
660+
ANOTHER_VALUE: { description: '' },
661+
},
662+
});
663+
664+
const someDirective = new GraphQLDirective({
665+
name: 'someDirective',
666+
description: '',
667+
args,
668+
locations: [DirectiveLocation.QUERY],
669+
});
670+
671+
const schema = new GraphQLSchema({
672+
description: '',
673+
query: queryType,
674+
types: [scalarType, interfaceType, unionType, enumType],
675+
directives: [someDirective],
625676
});
626677

627678
expectPrintedSchema(schema).to.equal(dedent`
679+
""""""
680+
schema {
681+
query: Query
682+
}
683+
684+
""""""
685+
directive @someDirective(
686+
""""""
687+
someArg: String
688+
689+
""""""
690+
anotherArg: String
691+
) on QUERY
692+
693+
""""""
694+
scalar SomeScalar
695+
696+
""""""
697+
interface SomeInterface {
698+
""""""
699+
someField(
700+
""""""
701+
someArg: String
702+
703+
""""""
704+
anotherArg: String
705+
): String
706+
707+
""""""
708+
anotherField(
709+
""""""
710+
someArg: String
711+
712+
""""""
713+
anotherArg: String
714+
): String
715+
}
716+
717+
""""""
718+
union SomeUnion = Query
719+
720+
""""""
628721
type Query {
629722
""""""
630-
singleField: String
723+
someField(
724+
""""""
725+
someArg: String
726+
727+
""""""
728+
anotherArg: String
729+
): String
730+
731+
""""""
732+
anotherField(
733+
""""""
734+
someArg: String
735+
736+
""""""
737+
anotherArg: String
738+
): String
739+
}
740+
741+
""""""
742+
enum SomeEnum {
743+
""""""
744+
SOME_VALUE
745+
746+
""""""
747+
ANOTHER_VALUE
631748
}
632749
`);
633750
});

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' +
@@ -238,7 +238,7 @@ function printArgs(
238238
}
239239

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

0 commit comments

Comments
 (0)