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
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
- .accepted_params(*keys) ⇒ Object
- .clear_accepted_params ⇒ Object
-
.field_name(str = nil) ⇒ Object
Used to obtain the full
pathin the GraphQL query by usingbase_path. - .slice_params(kargs) ⇒ Object
Instance Method Summary collapse
- #access_point(path = []) ⇒ Object
-
#initialize(client, path: nil, base_path: nil) ⇒ Query
constructor
A new instance of Query.
-
#path(field_name = self.class.field_name) ⇒ Object
Resolves the
pathby usingpathorbase_path+class.field_name. -
#query(path: self.path, **kargs, &block) ⇒ Class
Query rely that manages the different blocks.
- #response_class ⇒ Object
Constructor Details
#initialize(client, path: nil, base_path: nil) ⇒ Query
Returns a new instance of Query.
44 45 46 47 48 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 44 def initialize(client, path: nil, base_path: nil) @path = path @base_path = base_path @client = client end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
42 43 44 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 42 def base_path @base_path end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
41 42 43 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 41 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 |
.field_name(str = nil) ⇒ Object
Note:
it is meant for reusability of queries from different end-points
Used to obtain the full path in the GraphQL query by using base_path
33 34 35 36 37 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 33 def field_name(str = nil) return @field_name unless str @field_name = nil @field_name = str.to_s if str 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
68 69 70 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 68 def access_point(path = []) path.last end |
#path(field_name = self.class.field_name) ⇒ Object
Resolves the path by using path or base_path + class.field_name.
51 52 53 54 55 56 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 51 def path(field_name = self.class.field_name) result = @path result ||= default_path if self.respond_to?(:default_path, true) result ||= (base_path + [field_name]) if base_path && field_name result end |
#query(path: self.path, **kargs, &block) ⇒ Class
Query rely that manages the different blocks.
60 61 62 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 60 def query(path: self.path, **kargs, &block) graphql_query(path: path, **kargs, &basic_block(&block)) end |
#response_class ⇒ Object
64 65 66 |
# File 'lib/ecoportal/api/graphql/base/query.rb', line 64 def response_class item_class end |