Sha256: df3363a91fb1a6d51ba7130cb7099cd2d1c6dfb282f7ad7cf8c6ac95d9b9ac50

Contents?: true

Size: 907 Bytes

Versions: 2

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module GraphQL
  module Client
    module Query
      class Fragment
        include AddInlineFragment
        include HasSelectionSet

        attr_reader :document, :name, :type

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

          yield self if block_given?
        end

        def resolver_type
          type
        end

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

        def to_query(indent: '')
          "#{indent}...#{name}"
        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/fragment.rb
graphql_client-0.3.3 lib/graphql_client/query/fragment.rb