ecoportal-api-graphql 0.1.8 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b3cd9bc9cd023b6bf5d146de136fbdd617fea7f60d9f12a01abdb7ba87645e2
4
- data.tar.gz: fe14a47cf34fb401a5e563fbc4c30bfdb392d2f3129e841ff89bb8f06076f3d5
3
+ metadata.gz: 76cdada612c878305f9e858213257fc1a9f92ebc2997ed71295b81e987344cb3
4
+ data.tar.gz: 9554e3751ad19aa4de5b66d4d949f8fd77d9e5ad63c15ad2b17c1806e02d5c8b
5
5
  SHA512:
6
- metadata.gz: 8a3c50b23152c2c7acd777139c616d6087e83bc91a69864a54085bbf1beb64861cbf0fecbaa4d23e059fa7f814a52a5bc6f376b76434e6dea09014ed26c19616
7
- data.tar.gz: 07b0ba2a2c94e0d058e105d655697aaf6ea9cfeed6c2eb71b8ded614dcb0eb282cf9ded815e83bfff9a9fa2ef4eb97c68bd0b70476ac1cfef415588c1c8099c3
6
+ metadata.gz: d5f0a0fcf7e9e123ec91387f07084e0d92bebe6e5ec4d642a2a1906b382e4eeece58caeac8543938ebb04da22bf67f8eb89082e7062b2b7f990f81674f0dbb5e
7
+ data.tar.gz: 8dee0453e5d49178e107bc567ceb93d5150cfd0e2f024a1db3e36e928718f3dece27bdceb2c17a2fe10bb34e6bec62bd217d62ed490f18f3ea2eb9aa92983c08
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ Gemfile.lock
19
19
  # rspec failure tracking
20
20
  .rspec_status
21
21
  scratch.rb
22
+ tests/.byebug_history
data/CHANGELOG.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.1.9] - 2022-09-xx
4
+ ## [0.1.10] - 2022-09-xx
5
5
 
6
6
  ### Added
7
- ### Changed
7
+ ### Changed
8
8
  ### Fixed
9
9
 
10
10
  ### ToDo
@@ -14,6 +14,25 @@ All notable changes to this project will be documented in this file.
14
14
  - Analyse how to "DSL" currentOrganization.action.activities
15
15
  - review `path` tracking
16
16
 
17
+ ## [0.1.10] - 2022-09-29
18
+
19
+ ### Changed
20
+ - **upgraded** `ecoportal-api-v2` gem dependency
21
+
22
+ ### Fixed
23
+ - Remove debugging message
24
+
25
+ ## [0.1.9] - 2022-09-26
26
+
27
+ ### Added
28
+ - `Ecoportal::API::GraphQL::Query::TagTree`
29
+
30
+ ### Changed
31
+ - **upgraded** `ecoportal-api-v2` gem dependency
32
+ - added `Ecoportal::API::Common::GraphQL::QueryIntegration`
33
+ - restructured `Ecoportal::API::GraphQL::Model::Organization` class
34
+ - **Patch** on `Graphlient::Query` for fragments support (**pull request**: https://github.com/ashkan18/graphlient/pull/94)
35
+
17
36
  ## [0.1.8] - 2022-09-23
18
37
 
19
38
  ### Added
@@ -23,8 +42,6 @@ All notable changes to this project will be documented in this file.
23
42
  - **upgraded** `ecoportal-api-v2` gem dependency
24
43
  - Restructured the `Query` inheritance chain to make things simpler
25
44
 
26
- ### Fixed
27
-
28
45
  ## [0.1.6] - 2022-09-19
29
46
 
30
47
  ### Fixed
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "redcarpet", ">= 3.5.1", "< 3.6"
30
30
  spec.add_development_dependency "pry" , ">= 0.14"
31
31
 
32
- spec.add_dependency 'ecoportal-api-v2', '>= 0.8.33', '< 0.9'
32
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.9.2', '< 0.10'
33
33
  spec.add_dependency 'graphlient', '>= 0.6.0', '< 0.7'
34
34
  end
@@ -1,11 +1,33 @@
1
1
  module Graphlient
2
2
  class Query
3
+ FRAGMENT_DEFITION = /___(?<const>[A-Z][a-zA-Z0-9_]*(__[A-Z][a-zA-Z0-9_]*)*)/
4
+
5
+ def initialize(&block)
6
+ @indents = 0
7
+ @query_str = ''
8
+ @variables = []
9
+ evaluate(&block)
10
+ end
11
+
3
12
  private
4
13
 
5
- def append_node(node, args, arg_processor: nil, &block)
6
- if node.to_s.start_with?("___")
7
- node = node.to_s.gsub("___", "...").gsub("__", "::").to_sym
14
+ def evaluate(&block)
15
+ @last_block = block || self
16
+ (@context ||= {})[@last_block] ||= @last_block.binding
17
+ instance_eval(&block)
18
+ end
19
+
20
+ def resolve_fragment_constant(value)
21
+ return nil unless (match = value.to_s.match(FRAGMENT_DEFITION))
22
+ raw_const = match[:const].gsub('__', '::')
23
+ @context[@last_block].eval(raw_const).tap do |const|
24
+ msg = "Expected constant #{raw_const} to be GraphQL::Client::FragmentDefinition. Given #{const.class}"
25
+ raise Graphlient::Errors::Error, msg unless const.is_a? GraphQL::Client::FragmentDefinition
8
26
  end
27
+ end
28
+
29
+ def append_node(node, args, arg_processor: nil, &block)
30
+ node = "...#{resolve_fragment_constant(node)}".to_sym if node.to_s.start_with?('___')
9
31
 
10
32
  # add field
11
33
  @query_str << "\n#{indent}#{node}"
@@ -16,7 +38,7 @@ module Graphlient
16
38
  if block_given?
17
39
  @indents += 1
18
40
  @query_str << '{'
19
- instance_eval(&block)
41
+ evaluate(&block)
20
42
  @query_str << '}'
21
43
  @indents -= 1
22
44
  end
@@ -0,0 +1,41 @@
1
+ module Ecoportal
2
+ module API
3
+ module Common
4
+ module GraphQL
5
+ module QueryIntegration
6
+ include Ecoportal::API::Common::GraphQL::ClassHelpers::ClassMethods
7
+
8
+ attr_accessor :client
9
+ attr_reader :path
10
+
11
+ # @!macro [attach] query
12
+ # @method $1
13
+ # The $1 query integration
14
+ # @return [Collection::$1, $1]
15
+ # @return [Connection::$1, $1]
16
+ def query(method, query_klass:)
17
+ method = method.to_sym
18
+ class_method = "#{method}_query_class".to_sym
19
+
20
+ define_method(method) do |**kargs, &block|
21
+ if kargs.empty? && !block_given?
22
+ method(class_method).call
23
+ else
24
+ method(class_method).call.query(**kargs, &block)
25
+ end
26
+ end
27
+
28
+ define_method(class_method) do
29
+ resolve_class(query_klass).tap do |klass|
30
+ unless klass <= Ecoportal::API::GraphQL::Base::Query
31
+ raise "Expected query_klass to be of type Ecoportal::API::GraphQL::Base::Query. Given: #{klass}"
32
+ end
33
+ end.new(client, base_path: path)
34
+ end
35
+ private class_method
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -14,3 +14,4 @@ require 'ecoportal/api/common/graphql/class_helpers'
14
14
  require 'ecoportal/api/common/graphql/doc_helpers'
15
15
  require 'ecoportal/api/common/graphql/hash_helpers'
16
16
  require 'ecoportal/api/common/graphql/patches'
17
+ require 'ecoportal/api/common/graphql/query_integration'
@@ -18,7 +18,6 @@ module Ecoportal
18
18
  item_class,
19
19
  inherits: Ecoportal::API::Common::Content::CollectionModel
20
20
  ) do |klass|
21
- puts "created class #{klass}: item_class: #{item_class}"
22
21
  klass.klass = item_class
23
22
  end
24
23
  end
@@ -6,61 +6,24 @@ module Ecoportal
6
6
  DEFAULT_PATH = ["currentOrganization"]
7
7
 
8
8
  class << self
9
+ extend Ecoportal::API::Common::GraphQL::QueryIntegration
10
+
9
11
  def path(*add)
10
12
  DEFAULT_PATH.dup.push(*add)
11
13
  end
12
14
 
13
- #userGroup, userGroups
14
-
15
- # @return [Collection::TagTree, Query::TagTrees]
16
- def tagTrees(**kargs, &block)
17
- if kargs.empty? && !block_given?
18
- tagTreesQuery
19
- else
20
- tagTreesQuery.query(**kargs, &block)
21
- end
22
- end
23
-
24
- #tagTree
25
-
26
- #register, registers
27
- #personMembers, attachablePersonMembers
15
+ query :tagTree, query_klass: "Ecoportal::API::GraphQL::Query::TagTree"
16
+ query :tagTrees, query_klass: "Ecoportal::API::GraphQL::Query::TagTrees"
17
+ query :contractorEntities, query_klass: "Ecoportal::API::GraphQL::Query::ContractorEntities"
28
18
  #contractorEntity,
29
-
30
- # @return [Connection::ContractorEntity, Query::ContractorEntities]
31
- def contractorEntities(**kargs, &block)
32
- if kargs.empty? && !block_given?
33
- contractorEntitiesQuery
34
- else
35
- contractorEntitiesQuery.query(**kargs, &block)
36
- end
37
- end
38
-
39
- # @return [Connection::Action, Query::Actions]
40
- def actions(**kargs, &block)
41
- if kargs.empty? && !block_given?
42
- actionsQuery
43
- else
44
- actionsQuery.query(**kargs, &block)
45
- end
46
- end
47
-
19
+ query :actions, query_klass: "Ecoportal::API::GraphQL::Query::Actions"
48
20
  #action, actionsByPage, actionsCounter
49
21
  #actionCategories
50
22
 
51
- private
52
-
53
- def tagTreesQuery
54
- Ecoportal::API::GraphQL::Query::TagTrees.new(client, base_path: path)
55
- end
56
-
57
- def contractorEntitiesQuery
58
- Ecoportal::API::GraphQL::Query::ContractorEntities.new(client, base_path: path)
59
- end
23
+ #userGroup, userGroups
60
24
 
61
- def actionsQuery
62
- Ecoportal::API::GraphQL::Query::Actions.new(client, base_path: path)
63
- end
25
+ #register, registers
26
+ #personMembers, attachablePersonMembers
64
27
  end
65
28
  end
66
29
  end
@@ -0,0 +1,38 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Query
5
+ class TagTree < Ecoportal::API::GraphQL::Base::Query
6
+ accepted_params :id
7
+ field_name :tagTree
8
+
9
+ class_resolver :item_class, Ecoportal::API::GraphQL::Model::TagTree
10
+
11
+ private
12
+
13
+ def basic_block(&block)
14
+ final_block = block || default_tree_block
15
+ Proc.new {
16
+ query(id: :id!) {
17
+ currentOrganization {
18
+ tagTree(id: :id, &final_block)
19
+ }
20
+ }
21
+ }
22
+ end
23
+
24
+ def default_tree_block
25
+ Proc.new {
26
+ id
27
+ name
28
+ visitorManagementEnabled
29
+ nodes {
30
+ ___Ecoportal__API__GraphQL__Fragment__TagTreeNode
31
+ }
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -7,6 +7,7 @@ module Ecoportal
7
7
  end
8
8
  end
9
9
 
10
+ require 'ecoportal/api/graphql/query/tag_tree'
10
11
  require 'ecoportal/api/graphql/query/tag_trees'
11
12
  require 'ecoportal/api/graphql/query/actions'
12
13
  require 'ecoportal/api/graphql/query/contractor_entities'
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GRAPQL_VERSION = "0.1.8"
3
+ GRAPQL_VERSION = "0.1.10"
4
4
  end
5
5
  end
data/tests/local_libs.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'byebug'
1
2
  base_dir = 'C:/ruby_scripts/git'
2
3
 
3
4
  api_path = File.join(base_dir,'/ecoportal-api/lib')
@@ -10,8 +11,9 @@ api_v2_path = File.join(base_dir,'/ecoportal-api-v2/lib')
10
11
  $LOAD_PATH.unshift File.expand_path(api_v2_path)
11
12
  #require 'ecoportal/api-v2'
12
13
  require File.join(base_dir,'/ecoportal-api-v2/lib/ecoportal/api-v2')
13
- api_path = '../lib'
14
- $LOAD_PATH.unshift File.expand_path(api_path)
14
+
15
+ # $LOAD_PATH.unshift File.join(base_dir,'/graphlient/lib')
16
+ # require File.join(base_dir,'/graphlient/lib/graphlient')
15
17
 
16
18
  graphql = File.join(base_dir,'/ecoportal-api-graphql/lib')
17
19
  $LOAD_PATH.unshift File.expand_path(graphql)
@@ -0,0 +1,7 @@
1
+ require_relative 'local_libs'
2
+
3
+ api = Ecoportal::API::GraphQL.new
4
+ api.currentOrganization.tagTree(id: "6154d517860cb700112b7c99").tap do |tree|
5
+ puts "'#{tree.name}' (#{tree.id})"
6
+ pp tree.treeify
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api-graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,20 +130,20 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 0.8.33
133
+ version: 0.9.2
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
- version: '0.9'
136
+ version: '0.10'
137
137
  type: :runtime
138
138
  prerelease: false
139
139
  version_requirements: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: 0.8.33
143
+ version: 0.9.2
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
- version: '0.9'
146
+ version: '0.10'
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: graphlient
149
149
  requirement: !ruby/object:Gem::Requirement
@@ -196,6 +196,7 @@ files:
196
196
  - lib/ecoportal/api/common/graphql/http_client.rb
197
197
  - lib/ecoportal/api/common/graphql/patches.rb
198
198
  - lib/ecoportal/api/common/graphql/patches/query.rb
199
+ - lib/ecoportal/api/common/graphql/query_integration.rb
199
200
  - lib/ecoportal/api/graphql.rb
200
201
  - lib/ecoportal/api/graphql/base.rb
201
202
  - lib/ecoportal/api/graphql/base/action.rb
@@ -259,11 +260,13 @@ files:
259
260
  - lib/ecoportal/api/graphql/query.rb
260
261
  - lib/ecoportal/api/graphql/query/actions.rb
261
262
  - lib/ecoportal/api/graphql/query/contractor_entities.rb
263
+ - lib/ecoportal/api/graphql/query/tag_tree.rb
262
264
  - lib/ecoportal/api/graphql/query/tag_trees.rb
263
265
  - lib/ecoportal/api/graphql_version.rb
264
266
  - tests/actions_get.rb
265
267
  - tests/contractor_entities_get.rb
266
268
  - tests/local_libs.rb
269
+ - tests/tagtree_get.rb
267
270
  - tests/tagtrees_get.rb
268
271
  homepage: https://www.ecoportal.com
269
272
  licenses: