Sha256: 61d8cdfb5123cdaeae4551759ce3f6e26f503fac4c91aee8e7d4a6331e1c1f8e

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

module GraphQL::Relay::Walker
  class Frame
    attr_reader :queue, :gid, :parent, :context
    attr_accessor :result

    # Initialize a new Frame.
    #
    # queue  - The Queue that this frame belongs to.
    # gid    - The String GID.
    # parent - The Frame where this GID was discovered.
    #
    # Returns nothing.
    def initialize(queue, gid, parent)
      @queue   = queue
      @gid     = gid
      @parent  = parent
      @context = {}
    end

    # Add each found GID to the queue.
    #
    # Returns nothing.
    def enqueue_found_gids
      found_gids.each { |gid| queue.add(child(gid)) }
    end

    # Make a new frame with the given GID and this frame as its parent.
    #
    # gid - The String GID to create the frame with.
    #
    # Returns a Frame instance.
    def child(gid)
      Frame.new(queue, gid, self)
    end

    # The GIDs from this frame's results.
    #
    # Returns an Array of GID Strings.
    def found_gids(data=result)
      [].tap do |ids|
        case data
        when Hash
          ids.concat(Array(data["id"]))
          ids.concat(found_gids(data.values))
        when Array
          data.each { |datum| ids.concat(found_gids(datum)) }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
graphql-relay-walker-0.0.9 lib/graphql/relay/walker/frame.rb
graphql-relay-walker-0.0.8 lib/graphql/relay/walker/frame.rb
graphql-relay-walker-0.0.7 lib/graphql/relay/walker/frame.rb
graphql-relay-walker-0.0.6 lib/graphql/relay/walker/frame.rb
graphql-relay-walker-0.0.5 lib/graphql/relay/walker/frame.rb
graphql-relay-walker-0.0.4 lib/graphql/relay/walker/frame.rb
graphql-relay-walker-0.0.3 lib/graphql/relay/walker/frame.rb