module Ecoportal module API class GraphQL module Base class Query class GenericItem def initialize(*args, **kargs) raise "Missuse error. You should define a item_class for a class that inherits from Query class." end end include Ecoportal::API::Common::GraphQL::ClassHelpers inheritable_attrs :accepted_params class << self def accepted_params(*keys) @accepted_params ||= [] return @accepted_params if keys.empty? @accepted_params.push(*keys).tap {|ks| ks.uniq!} end def clear_accepted_params @accepted_params = [] end def slice_params(kargs) kargs.slice(*accepted_params) end end class_resolver :item_class, GenericItem attr_reader :client def initialize(client) @client = client end def response_class item_class end def access_point(path = []) path.last end def request(*path) response = yield wrap_response(response, path) end def wrap_response(response, path = []) raise "Complete failure on request. Path: #{path}" unless res = response.to_h.dig("data", *path) data = Ecoportal::API::Common::GraphQL::HashHelpers.deep_dup(res) response_class.new(data) end end end end end end