lib/ecoportal/api/graphql/base/query.rb in ecoportal-api-graphql-0.1.10 vs lib/ecoportal/api/graphql/base/query.rb in ecoportal-api-graphql-0.1.11

- old
+ new

@@ -37,11 +37,10 @@ end end class_resolver :item_class, GenericItem attr_reader :client - attr_reader :base_path def initialize(client, path: nil, base_path: nil) @path = path @base_path = base_path @@ -55,11 +54,11 @@ result ||= (base_path + [field_name]) if base_path && field_name result end # Query rely that manages the different blocks. - # @return [Class] an object of `response_class` with the results hanving from `path`. + # @return [Class] an object of `response_class` with the results hanging from `path`. def query(path: self.path, **kargs, &block) graphql_query(path: path, **kargs, &basic_block(&block)) end def response_class @@ -70,10 +69,14 @@ path.last end private + def basic_block + raise "This method should be implemented in the child class #{self.class}" + end + def graphql_query(path: self.path, **kargs, &block) query_params = self.class.slice_params(kargs) request(*path) do client.query(query_params, &block) end @@ -87,10 +90,10 @@ 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) + raise "Complete failure on request. Path: #{path}" unless res = response.to_h.dig(*path.dup.unshift("data")) data = Ecoportal::API::Common::GraphQL::HashHelpers.deep_dup(res) response_class.new(data) end end end