Sha256: 2552b70be10fb71cd867929e82d72744fd5f50e8f476664227b3de6525be642c

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

module Ecoportal
  module API
    module Common
      module GraphQL
        module QueryIntegration
          include Ecoportal::API::Common::GraphQL::ClassHelpers::ClassMethods

          attr_accessor :client
          attr_reader :path

          # @!macro [attach] query
          #   @method $1
          #   The $1 query integration
          #   @return [Collection::$1, $1]
          #   @return [Connection::$1, $1]
          def query(method, query_klass:, subpath: [])
            method = method.to_sym
            class_method = "#{method}_query_class".to_sym

            define_method(method) do |**kargs, &block|
              if kargs.empty? && !block_given?
                method(class_method).call
              else
                method(class_method).call.query(**kargs, &block)
              end
            end

            define_method(class_method) do
              final_path = path + [subpath].flatten.compact
              resolve_class(query_klass).tap do |klass|
                unless klass <= Ecoportal::API::GraphQL::Logic::Query
                  raise "Expected query_klass to be of type Ecoportal::API::GraphQL::Logic::Query. Given: #{klass}"
                end
              end.new(client, base_path: final_path)
            end
            private class_method
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.3.7 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.6 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.5 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.3 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.1 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.2.3 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.2.2 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.2.1 lib/ecoportal/api/common/graphql/query_integration.rb