Skip to content

Commit

Permalink
Add support for input object definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavbohac committed May 24, 2024
1 parent bda6e99 commit b714d23
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/graphql/language/nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ class EnumTypeExtension < AbstractNode
end

class InputObjectTypeDefinition < AbstractNode
attr_reader :description
attr_reader :comment, :description
scalar_methods :name
children_methods({
directives: GraphQL::Language::Nodes::Directive,
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/language/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def definition
name = parse_name
directives = parse_directives
input_fields_definition = parse_input_object_field_definitions
InputObjectTypeDefinition.new(pos: loc, definition_pos: defn_loc, description: desc, name: name, directives: directives, fields: input_fields_definition, filename: @filename, source: self)
InputObjectTypeDefinition.new(pos: loc, definition_pos: defn_loc, description: desc, comment: comment, name: name, directives: directives, fields: input_fields_definition, filename: @filename, source: self)
else
expect_one_of([:SCHEMA, :SCALAR, :TYPE, :ENUM, :INPUT, :UNION, :INTERFACE])
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/language/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def print_enum_value_definition(enum_value)
end

def print_input_object_type_definition(input_object_type, extension: false)
extension ? print_string("extend ") : print_description(input_object_type)
extension ? print_string("extend ") : print_description_and_comment(input_object_type)
print_string("input ")
print_string(input_object_type.name)
print_directives(input_object_type.directives)
Expand Down
15 changes: 14 additions & 1 deletion spec/graphql/language/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
end

describe "string comment" do
it "is parsed for fields, unions, interfaces, enums, enum values and arguments" do
it "is parsed for fields, unions, interfaces, enums, enum values, inputs and arguments" do
document = subject.parse <<-GRAPHQL
# type comment
type Thing {
Expand All @@ -223,6 +223,12 @@
interface CustomInterface {
name: String!
}
# Input comment
input CustomInput {
# Custom input name comment
name: String!
}
GRAPHQL

thing_defn = document.definitions[0]
Expand Down Expand Up @@ -252,6 +258,13 @@

custom_interface_defn = document.definitions[4]
assert_equal "Interface comment", custom_interface_defn.comment

custom_input_defn = document.definitions[5]
assert_equal "Input comment", custom_input_defn.comment

input_field_defn = custom_input_defn.fields[0]
assert_equal "name", input_field_defn.name
assert_equal "Custom input name comment", input_field_defn.comment
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/graphql/language/printer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"""
Input description
"""
# Input type comment
input InputType {
key: String!
answer: Int = 42
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/schema/input_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
it "has it" do
assert_equal "EnsembleInput", input_object.graphql_name
assert_nil input_object.description
assert_equal "Ensemble input comment", input_object.comment
assert_equal 1, input_object.arguments.size
end

Expand Down
2 changes: 2 additions & 0 deletions spec/support/jazz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ def nullable_ensemble(ensemble: nil)
end

class EnsembleInput < GraphQL::Schema::InputObject
comment "Ensemble input comment"

argument :name, String
end

Expand Down

0 comments on commit b714d23

Please sign in to comment.