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

Don't print empty braces when input object has no arguments #4138

Merged
merged 1 commit into from Jul 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/graphql/language/printer.rb
Expand Up @@ -236,12 +236,15 @@ def print_input_object_type_definition(input_object_type)
out = print_description(input_object_type)
out << "input #{input_object_type.name}"
out << print_directives(input_object_type.directives)
out << " {\n"
input_object_type.fields.each.with_index do |field, i|
out << print_description(field, indent: ' ', first_in_block: i == 0)
out << " #{print_input_value_definition(field)}\n"
if !input_object_type.fields.empty?
out << " {\n"
input_object_type.fields.each.with_index do |field, i|
out << print_description(field, indent: ' ', first_in_block: i == 0)
out << " #{print_input_value_definition(field)}\n"
end
out << "}"
end
out << "}"
out
end

def print_directive_definition(directive)
Expand Down
15 changes: 12 additions & 3 deletions spec/graphql/schema/printer_spec.rb
Expand Up @@ -70,6 +70,9 @@ class Media < GraphQL::Schema::Union
class NoFields < GraphQL::Schema::Object
end

class NoArguments < GraphQL::Schema::InputObject
end

class Query < GraphQL::Schema::Object
description "The query root of this schema"

Expand All @@ -80,7 +83,9 @@ class Query < GraphQL::Schema::Object
argument :deprecated_arg, String, required: false, deprecation_reason: "Use something else"
end

field :no_fields_type, NoFields
field :no_fields_type, NoFields do
argument :no_arguments_input, NoArguments
end
end

class CreatePost < GraphQL::Schema::RelayClassicMutation
Expand Down Expand Up @@ -531,6 +536,8 @@ class Subscription < GraphQL::Schema::Object
): CreatePostPayload
}

input NoArguments

type NoFields

interface Node {
Expand All @@ -552,7 +559,7 @@ class Subscription < GraphQL::Schema::Object
The query root of this schema
"""
type Query {
noFieldsType: NoFields
noFieldsType(noArgumentsInput: NoArguments!): NoFields
post(
deprecatedArg: String @deprecated(reason: "Use something else")

Expand Down Expand Up @@ -721,6 +728,8 @@ def foobar
): CreatePostPayload
}

input NoArguments

type NoFields

interface Node {
Expand All @@ -741,7 +750,7 @@ def foobar
The query root of this schema
"""
type Query {
noFieldsType: NoFields
noFieldsType(noArgumentsInput: NoArguments!): NoFields
post(
"""
Post ID
Expand Down