Class: Ecoportal::API::GraphQL::Base::Query
- Inherits:
-
Object
- Object
- Ecoportal::API::GraphQL::Base::Query
- Includes:
- Common::GraphQL::ClassHelpers
- Defined in:
- lib/ecoportal/api/graphql/base/query.rb
Direct Known Subclasses
Defined Under Namespace
Classes: GenericItem
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
- #access_point(path = []) ⇒ Object
-
#initialize(client) ⇒ Query
constructor
A new instance of Query.
- #request(*path) ⇒ Object
- #response_class ⇒ Object
- #wrap_response(response, path = []) ⇒ Object
Constructor Details
#initialize(client) ⇒ Query
Returns a new instance of Query.
35 36 37 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 35 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
33 34 35 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 33 def client @client end |
Class Method Details
.accepted_params(*keys) ⇒ Object
17 18 19 20 21 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 17 def accepted_params(*keys) @accepted_params ||= [] return @accepted_params if keys.empty? @accepted_params.push(*keys).tap {|ks| ks.uniq!} end |
.clear_accepted_params ⇒ Object
23 24 25 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 23 def clear_accepted_params @accepted_params = [] end |
.slice_params(kargs) ⇒ Object
27 28 29 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 27 def slice_params(kargs) kargs.slice(*accepted_params) end |
Instance Method Details
#access_point(path = []) ⇒ Object
43 44 45 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 43 def access_point(path = []) path.last end |
#request(*path) ⇒ Object
47 48 49 50 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 47 def request(*path) response = yield wrap_response(response, path) end |
#response_class ⇒ Object
39 40 41 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 39 def response_class item_class end |
#wrap_response(response, path = []) ⇒ Object
52 53 54 55 56 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 52 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 |