Module: Ecoportal::API::Common::GraphQL::QueryIntegration
- Includes:
- ClassHelpers::ClassMethods
- Included in:
- GraphQL::Model::Organization
- Defined in:
- lib/ecoportal/api/common/graphql/query_integration.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#method ⇒ Collection::method, ...
The method query integration.
-
#query(method, query_klass:, subpath: []) ⇒ Collection::method, ...
The method query integration.
Methods included from ClassHelpers::ClassMethods
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/ecoportal/api/common/graphql/query_integration.rb', line 8 def client @client end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/ecoportal/api/common/graphql/query_integration.rb', line 9 def path @path end |
Instance Method Details
#method ⇒ Collection::method, ...
The method query integration
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ecoportal/api/common/graphql/query_integration.rb', line 16 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 |
#query(method, query_klass:, subpath: []) ⇒ Collection::method, ...
The method query integration
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ecoportal/api/common/graphql/query_integration.rb', line 16 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 |