ecoportal-api-graphql 0.1.4 → 0.1.6

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: 5ebcd32d52a269e3f9b9348fdb9e3ca80b3c07a75872e67759d978cd57c233d2
4
- data.tar.gz: 80bbb9bbaa4a8a420b028cb3f5d4f1685621e176a239710024cede3ab12eed87
3
+ metadata.gz: 7c0e5dcda795491dd4687054d51f9b3888f707f320ed079742c54cbde74464ad
4
+ data.tar.gz: ab434f8f1f410692b0ac8f4a3cd549293045e17e469b2b09a14c1fbe85123f06
5
5
  SHA512:
6
- metadata.gz: cdbb369046537a6916711f0bbae1cb7a4edd443c6ce19e97bcc529eb6eab72805dd16714aa5a6d165da6690d46d9a0e28e406d036551a6c51b787fd3f44addfb
7
- data.tar.gz: 0a3f51c9733e66af42edaf63b2c93546cb8ec929fbecfa0dc70a555d9fd846f0228322d2bd85695044e0ac3b875266ae9e3a622f5226d759ebcf1345f287979f
6
+ metadata.gz: f3d127b631c0c567cd7831d5e1cda50f5474e1d4c262716e000aa324045b2fc228452ed2d968b620b9b58c43000b4526af5d2916e525b81af2c12999e23a00bd
7
+ data.tar.gz: 5c86f610a220829e975bef5ff3e459801247a7cda07368dafc2fc2278b81aed8f2535b187b6ee8682d61bc15bfb23ea84c048dac6df48c219d6f4ccb5fff84bd
data/CHANGELOG.md CHANGED
@@ -1,12 +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.5] - 2022-09-xx
4
+ ## [0.1.7] - 2022-09-xx
5
5
 
6
6
  ### Added
7
-
8
7
  ### Changed
9
-
10
8
  ### Fixed
11
9
 
12
10
  ### ToDo
@@ -16,13 +14,27 @@ All notable changes to this project will be documented in this file.
16
14
  - Analyse how to "DSL" currentOrganization.action.activities
17
15
  - review `path` tracking
18
16
 
17
+ ## [0.1.6] - 2022-09-19
18
+
19
+ ### Fixed
20
+ - Call to **private** method `remove_const` in `Ecoportal::API::GraphQL::Fragment#define`
21
+
22
+ ## [0.1.5] - 2022-09-19
23
+
24
+ ### Added
25
+ - Patch `GraphQL::Query#append_node` so we can use Fragments in blocks using `___` as start of the constant, and `__` for namespace separator
26
+ - Issue/feature request: https://github.com/ashkan18/graphlient/issues/93
27
+ - `Ecoportal::API::GraphQL::Fragment#define` provided that client scripts can create their own fragments in their own namespace
28
+ - Exposed `Ecoportal::API::GraphQL#fragments`
29
+ - It will always (re)define in the `Fragment` root namespace
30
+
19
31
  ## [0.1.4] - 2022-09-16
20
32
 
21
33
  ### Fixed
22
34
  - Able to inject connection block to `each`
23
35
  - Error handling delegated to parent class (`QueryConnection`)
24
36
  - Retrieve `id` on elements of `Array`
25
-
37
+
26
38
  ## [0.1.3] - 2022-09-15
27
39
 
28
40
  ### Fixed
@@ -1,4 +1,3 @@
1
- require 'graphlient'
2
1
  module Ecoportal
3
2
  module API
4
3
  module Common
@@ -19,6 +19,15 @@ module Ecoportal
19
19
 
20
20
  module ClassMethods
21
21
  include Ecoportal::API::Common::Content::ClassHelpers
22
+
23
+ def const?(value)
24
+ begin
25
+ const_get(value)
26
+ rescue NameError => e
27
+ return false
28
+ end
29
+ true
30
+ end
22
31
  end
23
32
 
24
33
  class << self
@@ -0,0 +1,27 @@
1
+ module Graphlient
2
+ class Query
3
+ private
4
+
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
8
+ end
9
+
10
+ # add field
11
+ @query_str << "\n#{indent}#{node}"
12
+ # add filter
13
+ hash_arguments = hash_arg(args)
14
+ @query_str << "(#{args_str(hash_arguments, arg_processor: arg_processor)})" if hash_arguments
15
+
16
+ if block_given?
17
+ @indents += 1
18
+ @query_str << '{'
19
+ instance_eval(&block)
20
+ @query_str << '}'
21
+ @indents -= 1
22
+ end
23
+
24
+ @query_str << "\n#{indent}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require_relative 'patches/query'
@@ -13,3 +13,4 @@ require 'ecoportal/api/common/graphql/client'
13
13
  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
+ require 'ecoportal/api/common/graphql/patches'
@@ -0,0 +1,53 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ class Fragment
5
+ fragment :Action, <<~'GRAPHQL'
6
+ fragment on Action {
7
+ id
8
+ altId
9
+ actionCategory {
10
+ name
11
+ value
12
+ }
13
+ standaloneAction
14
+ status
15
+ relativeStatus
16
+ archived
17
+ tags
18
+ name
19
+ description
20
+ assignedTo {
21
+ id
22
+ name
23
+ email
24
+ }
25
+ createdAt {
26
+ dateTime
27
+ timeZone
28
+ }
29
+ dueDate {
30
+ dateTime
31
+ timeZone
32
+ }
33
+ completedAt {
34
+ dateTime
35
+ timeZone
36
+ }
37
+ completer {
38
+ name
39
+ email
40
+ }
41
+ linkedResources {
42
+ id
43
+ page {
44
+ name
45
+ mouldCounter
46
+ }
47
+ }
48
+ }
49
+ GRAPHQL
50
+ end
51
+ end
52
+ end
53
+ end
@@ -3,7 +3,7 @@ module Ecoportal
3
3
  class GraphQL
4
4
  class Fragment
5
5
  fragment :Pagination, <<~'GRAPHQL'
6
- fragment on ContractorEntityConnection {
6
+ fragment on ActionConnection {
7
7
  totalCount
8
8
  pageInfo {
9
9
  endCursor
@@ -1,17 +1,15 @@
1
+ # Namespace to create custom fragments from client scripts
2
+ module Fragment
3
+ include Ecoportal::API::Common::GraphQL::ClassHelpers
4
+ end
5
+ # Class to define/parse fragments
1
6
  module Ecoportal
2
7
  module API
3
8
  class GraphQL
4
9
  class Fragment
5
- class << self
6
- def const?(value)
7
- begin
8
- const_get(value)
9
- rescue NameError => e
10
- return false
11
- end
12
- true
13
- end
10
+ include Ecoportal::API::Common::GraphQL::ClassHelpers
14
11
 
12
+ class << self
15
13
  def fragment(sym, heredoc)
16
14
  fragments[sym] = heredoc
17
15
  end
@@ -28,17 +26,19 @@ module Ecoportal
28
26
  parse
29
27
  end
30
28
 
29
+ def define(sym, heredoc, namespace: ::Fragment)
30
+ namespace.send(:remove_const, sym) if namespace.const?(sym)
31
+ client.parse(heredoc).tap do |fragment|
32
+ namespace.const_set(sym, fragment)
33
+ ::Fragment.const_set(sym, fragment) unless namespace == ::Fragment
34
+ end
35
+ end
36
+
31
37
  private
32
38
 
33
39
  def parse
34
40
  fragments = self.class.fragments.each_with_object({}) do |(sym, heredoc), out|
35
- if self.class.const?(sym)
36
- fragment = self.class.get_const(sym)
37
- else
38
- fragment = client.parse(heredoc)
39
- self.class.const_set(sym, fragment)
40
- end
41
- out[sym] = fragment
41
+ out[sym] = define(sym, heredoc, namespace: self.class)
42
42
  end
43
43
  end
44
44
  end
@@ -46,5 +46,6 @@ module Ecoportal
46
46
  end
47
47
  end
48
48
 
49
- require 'ecoportal/api/graphql/fragment/contractor_entity'
50
49
  require 'ecoportal/api/graphql/fragment/pagination'
50
+ require 'ecoportal/api/graphql/fragment/action'
51
+ require 'ecoportal/api/graphql/fragment/contractor_entity'
@@ -39,52 +39,9 @@ module Ecoportal
39
39
 
40
40
  def default_connection_block
41
41
  Proc.new {
42
- totalCount
43
- pageInfo {
44
- endCursor
45
- }
42
+ ___Ecoportal__API__GraphQL__Fragment__Pagination
46
43
  nodes {
47
- id
48
- altId
49
- actionCategory {
50
- name
51
- value
52
- }
53
- standaloneAction
54
- status
55
- relativeStatus
56
- archived
57
- tags
58
- name
59
- description
60
- assignedTo {
61
- id
62
- name
63
- email
64
- }
65
- createdAt {
66
- dateTime
67
- timeZone
68
- }
69
- dueDate {
70
- dateTime
71
- timeZone
72
- }
73
- completedAt {
74
- dateTime
75
- timeZone
76
- }
77
- completer {
78
- name
79
- email
80
- }
81
- linkedResources {
82
- id
83
- page {
84
- name
85
- mouldCounter
86
- }
87
- }
44
+ ___Ecoportal__API__GraphQL__Fragment__Action
88
45
  }
89
46
  }
90
47
  end
@@ -45,13 +45,7 @@ module Ecoportal
45
45
  endCursor
46
46
  }
47
47
  nodes {
48
- id
49
- name
50
- schemaId
51
- active
52
- approved
53
- associatedPeopleIds
54
- leadContractorIds
48
+ ___Ecoportal__API__GraphQL__Fragment__ContractorEntity
55
49
  }
56
50
  }
57
51
  end
@@ -5,7 +5,7 @@ module Ecoportal
5
5
  class GraphQL
6
6
  include Ecoportal::API::Common::GraphQL::ClassHelpers
7
7
 
8
- attr_reader :client
8
+ attr_reader :client, :fragments
9
9
 
10
10
  # Creates a `GraphQL` object to interact with the ecoPortal `GraphQL API`.
11
11
  # @param org_id [String] the id of the target organization.
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GRAPQL_VERSION = "0.1.4"
3
+ GRAPQL_VERSION = "0.1.6"
4
4
  end
5
5
  end
data/tests/actions_get.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require_relative 'local_libs'
2
- require 'ecoportal/api-graphql'
3
2
 
4
3
  api = Ecoportal::API::GraphQL.new
5
4
  api.currentOrganization.actions.each_with_index do |action, idx|
data/tests/local_libs.rb CHANGED
@@ -12,3 +12,7 @@ $LOAD_PATH.unshift File.expand_path(api_v2_path)
12
12
  require File.join(base_dir,'/ecoportal-api-v2/lib/ecoportal/api-v2')
13
13
  api_path = '../lib'
14
14
  $LOAD_PATH.unshift File.expand_path(api_path)
15
+
16
+ graphql = File.join(base_dir,'/ecoportal-api-graphql/lib')
17
+ $LOAD_PATH.unshift File.expand_path(graphql)
18
+ require_relative File.expand_path(File.join(graphql, 'ecoportal/api-graphql'))
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.4
4
+ version: 0.1.6
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-16 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -194,6 +194,8 @@ files:
194
194
  - lib/ecoportal/api/common/graphql/doc_helpers.rb
195
195
  - lib/ecoportal/api/common/graphql/hash_helpers.rb
196
196
  - lib/ecoportal/api/common/graphql/http_client.rb
197
+ - lib/ecoportal/api/common/graphql/patches.rb
198
+ - lib/ecoportal/api/common/graphql/patches/query.rb
197
199
  - lib/ecoportal/api/graphql.rb
198
200
  - lib/ecoportal/api/graphql/base.rb
199
201
  - lib/ecoportal/api/graphql/base/action.rb
@@ -220,6 +222,7 @@ files:
220
222
  - lib/ecoportal/api/graphql/connection/contractor_entity.rb
221
223
  - lib/ecoportal/api/graphql/connection/person_member.rb
222
224
  - lib/ecoportal/api/graphql/fragment.rb
225
+ - lib/ecoportal/api/graphql/fragment/action.rb
223
226
  - lib/ecoportal/api/graphql/fragment/contractor_entity.rb
224
227
  - lib/ecoportal/api/graphql/fragment/pagination.rb
225
228
  - lib/ecoportal/api/graphql/input.rb