diff --git a/lib/graphql/compatibility/schema_parser_specification.rb b/lib/graphql/compatibility/schema_parser_specification.rb index bfe86fd8af..5d1c754e67 100644 --- a/lib/graphql/compatibility/schema_parser_specification.rb +++ b/lib/graphql/compatibility/schema_parser_specification.rb @@ -595,31 +595,27 @@ def test_it_parses_whole_definition_with_descriptions assert_equal 6, document.definitions.size - schema_definition = document.definitions.shift + schema_definition, directive_definition, enum_type_definition, object_type_definition, input_object_type_definition, interface_type_definition = document.definitions + assert_equal GraphQL::Language::Nodes::SchemaDefinition, schema_definition.class - directive_definition = document.definitions.shift assert_equal GraphQL::Language::Nodes::DirectiveDefinition, directive_definition.class assert_equal 'This is a directive', directive_definition.description - enum_type_definition = document.definitions.shift assert_equal GraphQL::Language::Nodes::EnumTypeDefinition, enum_type_definition.class assert_equal "Multiline comment\n\nWith an enum", enum_type_definition.description assert_nil enum_type_definition.values[0].description assert_equal 'Not a creative color', enum_type_definition.values[1].description - object_type_definition = document.definitions.shift assert_equal GraphQL::Language::Nodes::ObjectTypeDefinition, object_type_definition.class assert_equal 'Comment without preceding space', object_type_definition.description assert_equal 'And a field to boot', object_type_definition.fields[0].description - input_object_type_definition = document.definitions.shift assert_equal GraphQL::Language::Nodes::InputObjectTypeDefinition, input_object_type_definition.class assert_equal 'Comment for input object types', input_object_type_definition.description assert_equal 'Color of the car', input_object_type_definition.fields[0].description - interface_type_definition = document.definitions.shift assert_equal GraphQL::Language::Nodes::InterfaceTypeDefinition, interface_type_definition.class assert_equal 'Comment for interface definitions', interface_type_definition.description assert_equal 'Amount of wheels', interface_type_definition.fields[0].description diff --git a/lib/graphql/language/document_from_schema_definition.rb b/lib/graphql/language/document_from_schema_definition.rb index 78dc153a75..6d43166955 100644 --- a/lib/graphql/language/document_from_schema_definition.rb +++ b/lib/graphql/language/document_from_schema_definition.rb @@ -65,7 +65,7 @@ def build_field_node(field) ) if field.deprecation_reason - field_node.directives << GraphQL::Language::Nodes::Directive.new( + field_node = field_node.merge_directive( name: GraphQL::Directive::DeprecatedDirective.name, arguments: [GraphQL::Language::Nodes::Argument.new(name: "reason", value: field.deprecation_reason)] ) @@ -107,7 +107,7 @@ def build_enum_value_node(enum_value) ) if enum_value.deprecation_reason - enum_value_node.directives << GraphQL::Language::Nodes::Directive.new( + enum_value_node = enum_value_node.merge_directive( name: GraphQL::Directive::DeprecatedDirective.name, arguments: [GraphQL::Language::Nodes::Argument.new(name: "reason", value: enum_value.deprecation_reason)] ) diff --git a/lib/graphql/language/nodes.rb b/lib/graphql/language/nodes.rb index 3e39c6e44e..d6e62b2038 100644 --- a/lib/graphql/language/nodes.rb +++ b/lib/graphql/language/nodes.rb @@ -168,7 +168,7 @@ def merge_#{method_name.to_s.sub(/s$/, "")}(node_opts) else module_eval <<-RUBY, __FILE__, __LINE__ def children - @children ||= #{children_of_type.keys.map { |k| "@#{k}" }.join(" + ")} + @children ||= (#{children_of_type.keys.map { |k| "@#{k}" }.join(" + ")}).freeze end RUBY end @@ -200,7 +200,7 @@ def scalar_methods(*method_names) attr_reader #{method_names.map { |m| ":#{m}"}.join(", ")} def scalars - @scalars ||= [#{method_names.map { |k| "@#{k}" }.join(", ")}] + @scalars ||= [#{method_names.map { |k| "@#{k}" }.join(", ")}].freeze end RUBY end @@ -224,7 +224,9 @@ def generate_initialize_node arguments = scalar_method_names.map { |m| "#{m}: nil"} + @children_methods.keys.map { |m| "#{m}: []" } - assignments = all_method_names.map { |m| "@#{m} = #{m}"} + assignments = scalar_method_names.map { |m| "@#{m} = #{m}"} + + @children_methods.keys.map { |m| "@#{m} = #{m}.freeze" } + module_eval <<-RUBY, __FILE__, __LINE__ def initialize_node #{arguments.join(", ")} #{assignments.join("\n")}