Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printSchema: correctly print empty description #3869

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 121 additions & 4 deletions src/utilities/__tests__/printSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,133 @@ describe('Type System Printer', () => {
`);
});

it('Prints an empty description', () => {
const schema = buildSingleFieldSchema({
type: GraphQLString,
it('Prints an empty descriptions', () => {
const args = {
someArg: { description: '', type: GraphQLString },
anotherArg: { description: '', type: GraphQLString },
};

const fields = {
someField: { description: '', type: GraphQLString, args },
anotherField: { description: '', type: GraphQLString, args },
};

const queryType = new GraphQLObjectType({
name: 'Query',
description: '',
fields,
});

const scalarType = new GraphQLScalarType({
name: 'SomeScalar',
description: '',
});

const interfaceType = new GraphQLInterfaceType({
name: 'SomeInterface',
description: '',
fields,
});

const unionType = new GraphQLUnionType({
name: 'SomeUnion',
description: '',
types: [queryType],
});

const enumType = new GraphQLEnumType({
name: 'SomeEnum',
description: '',
values: {
SOME_VALUE: { description: '' },
ANOTHER_VALUE: { description: '' },
},
});

const someDirective = new GraphQLDirective({
name: 'someDirective',
description: '',
args,
locations: [DirectiveLocation.QUERY],
});

const schema = new GraphQLSchema({
description: '',
query: queryType,
types: [scalarType, interfaceType, unionType, enumType],
directives: [someDirective],
});

expectPrintedSchema(schema).to.equal(dedent`
""""""
schema {
query: Query
}

""""""
directive @someDirective(
""""""
someArg: String

""""""
anotherArg: String
) on QUERY

""""""
scalar SomeScalar

""""""
interface SomeInterface {
""""""
someField(
""""""
someArg: String

""""""
anotherArg: String
): String

""""""
anotherField(
""""""
someArg: String

""""""
anotherArg: String
): String
}

""""""
union SomeUnion = Query

""""""
type Query {
""""""
singleField: String
someField(
""""""
someArg: String

""""""
anotherArg: String
): String

""""""
anotherField(
""""""
someArg: String

""""""
anotherArg: String
): String
}

""""""
enum SomeEnum {
""""""
SOME_VALUE

""""""
ANOTHER_VALUE
}
`);
});
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/printSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function printSchemaDefinition(schema: GraphQLSchema): Maybe<string> {

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

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

Expand Down