lib/graphql/language/nodes.rb in graphql-1.10.0.pre1 vs lib/graphql/language/nodes.rb in graphql-1.10.0.pre2

- old
+ new

@@ -26,11 +26,12 @@ # then calling the class's `initialize_node` method. # @param options [Hash] Initial attributes for this node def initialize(options={}) if options.key?(:position_source) position_source = options.delete(:position_source) - @line, @col = position_source.line_and_column + @line = position_source.line + @col = position_source.col end @filename = options.delete(:filename) initialize_node(options) @@ -64,11 +65,11 @@ @query_string = nil end # @return [Symbol] the method to call on {Language::Visitor} for this node def visit_method - raise NotImplementedError, "#{self.class.name}#visit_method shold return a symbol" + raise GraphQL::RequiredImplementationMissingError, "#{self.class.name}#visit_method shold return a symbol" end def position [line, col] end @@ -348,26 +349,28 @@ class NullValue < NameOnlyNode end # A single selection in a GraphQL query. class Field < AbstractNode + NONE = [].freeze + scalar_methods :name, :alias children_methods({ arguments: GraphQL::Language::Nodes::Argument, selections: GraphQL::Language::Nodes::Field, directives: GraphQL::Language::Nodes::Directive, }) # @!attribute selections # @return [Array<Nodes::Field>] Selections on this object (or empty array if this is a scalar field) - def initialize_node(name: nil, arguments: [], directives: [], selections: [], **kwargs) - @name = name - @arguments = arguments - @directives = directives - @selections = selections + def initialize_node(attributes) + @name = attributes[:name] + @arguments = attributes[:arguments] || NONE + @directives = attributes[:directives] || NONE + @selections = attributes[:selections] || NONE # oops, alias is a keyword: - @alias = kwargs.fetch(:alias, nil) + @alias = attributes[:alias] end # Override this because default is `:fields` def children_method_name :selections