Sha256: bacb9a29cae0f92baa2455481e03c600bc6f3ebd64e41929dcb1d192aad711c7

Contents?: true

Size: 745 Bytes

Versions: 2

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

module GraphQL
  module Client
    module Query
      class InlineFragment
        include HasSelectionSet

        attr_reader :document, :type

        def initialize(type, document:)
          @type = type
          @document = document
          @selection_set = SelectionSet.new

          yield self if block_given?
        end

        def resolver_type
          type
        end

        def to_query(indent: '')
          indent.dup.tap do |query_string|
            query_string << "... on #{type.name} {\n"
            query_string << selection_set.to_query(indent)
            query_string << "\n#{indent}}"
          end
        end

        alias_method :to_s, :to_query
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql_client-0.4.1 lib/graphql_client/query/inline_fragment.rb
graphql_client-0.3.3 lib/graphql_client/query/inline_fragment.rb