Sha256: b664a6c28ca7fb357ff380ef9868949927fd5302e1d28f9514328b9f7e4aaff0

Contents?: true

Size: 1.38 KB

Versions: 13

Compression:

Stored size: 1.38 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::BaseQuery
                  raise "Expected query_klass to be of type Ecoportal::API::GraphQL::Logic::BaseQuery. Given: #{klass}"
                end
              end.new(client, base_path: final_path)
            end
            private class_method
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ecoportal-api-graphql-0.4.3 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.4.2 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.4.1 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.4.0 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.16 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.15 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.14 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.13 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.12 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.11 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.10 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.9 lib/ecoportal/api/common/graphql/query_integration.rb
ecoportal-api-graphql-0.3.8 lib/ecoportal/api/common/graphql/query_integration.rb