ecoportal-api-graphql 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07ba83146627efb03fc8dff405390cafd4f5cfdb4ad2f3bc4411a49d42d8a259
4
- data.tar.gz: 7be60f892e80c06418312fe6f566cc57b7f8c23bd45ebc339305439df8e5ca80
3
+ metadata.gz: b4546feadd8f75c4df5ee12df6c7777a1e6e149a39df1e0dd774ea9453d52aa2
4
+ data.tar.gz: 2833d0fafea1d9d5ef7bbdf0812c00578d470ebd1cb126918e7b7a29e33643e4
5
5
  SHA512:
6
- metadata.gz: 59d820cad74807d561595cb157d92ec16094a028c1354501c8e5ea43efc4f962cee87f10bb0689055acd81839902319db4903bcd5ce8b4c1bbd84f97ff1fd2a2
7
- data.tar.gz: e60dea5941855d499dbdaa60f2f835607612560a11b047623adbbd5f71a646492c37df234d265ac05a932bd3e784194ac921580329b35b1aaf5a1e418b5b2af6
6
+ metadata.gz: 952bda5933f5e5c0d7b746f627aae46af22d011b58fd3e0c81615141deb4a487926bb6ba829d594b7b1987f5f4bc35aa17084401a9ab88f7cff5f470b38193df
7
+ data.tar.gz: abd9299ae5f9a915e7fbe372aeeffe30ae6e6132df7d65a880529b6037a5c2d249e19c7e5f982dedd867f8100dd95825f5c87cdc460663232bf49b16dac3921a
data/CHANGELOG.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.1.4] - 2022-09-xx
4
+ ## [0.1.6] - 2022-09-xx
5
5
 
6
6
  ### Added
7
7
 
@@ -16,6 +16,21 @@ All notable changes to this project will be documented in this file.
16
16
  - Analyse how to "DSL" currentOrganization.action.activities
17
17
  - review `path` tracking
18
18
 
19
+ ## [0.1.5] - 2022-09-19
20
+
21
+ ### Added
22
+ - Patch `GraphQL::Query#append_node` so we can use Fragments in blocks using `___` as start of the constant, and `__` for namespace separator
23
+ - Issue/feature request: https://github.com/ashkan18/graphlient/issues/93
24
+ - `Ecoportal::API::GraphQL::Fragment#define` provided that client scripts can create their own fragments in their own namespace
25
+ - Exposed `Ecoportal::API::GraphQL#fragments`
26
+ - It will always (re)define in the `Fragment` root namespace
27
+
28
+ ## [0.1.4] - 2022-09-16
29
+
30
+ ### Fixed
31
+ - Able to inject connection block to `each`
32
+ - Error handling delegated to parent class (`QueryConnection`)
33
+ - Retrieve `id` on elements of `Array`
19
34
 
20
35
  ## [0.1.3] - 2022-09-15
21
36
 
@@ -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'
@@ -20,12 +20,21 @@ module Ecoportal
20
20
  raise "Missuse. You have to implement this method in the child class"
21
21
  end
22
22
 
23
- def each(**kargs, &block)
24
- return to_enum(:each, **kargs) unless block
23
+ def graphql_query(**kargs, &block)
24
+ query_params = self.class.slice_params(kargs)
25
+ client.query(query_params, &block)
26
+ rescue Faraday::ParsingError => e
27
+ puts "Internal Error with these params:"
28
+ pp kargs
29
+ raise
30
+ end
31
+
32
+ def each(connection_block: nil, **kargs, &block)
33
+ return to_enum(:each, **kargs, connection_block: connection_block) unless block
25
34
  cursor = nil; results = 0
26
35
  loop do
27
36
  kargs.update(after: cursor) if cursor
28
- connection = query(**kargs)
37
+ connection = query(**kargs, &connection_block)
29
38
  #total = connection.totalCount
30
39
  pageInfo = connection.pageInfo
31
40
  connection.nodes.each do |item|
@@ -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.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'
@@ -8,10 +8,8 @@ module Ecoportal
8
8
 
9
9
  def query(path: default_base_path, **kargs, &block)
10
10
  path ||= default_base_path
11
- kargs = self.class.slice_params(kargs)
12
11
  request(*path, "actions") do
13
- next client.query(kargs, &basic_block(&block)) if block_given?
14
- client.query(kargs, &basic_block)
12
+ graphql_query(**kargs, &basic_block(&block))
15
13
  end
16
14
  end
17
15
 
@@ -41,49 +39,9 @@ module Ecoportal
41
39
 
42
40
  def default_connection_block
43
41
  Proc.new {
44
- totalCount
45
- pageInfo {
46
- endCursor
47
- }
42
+ ___Ecoportal__API__GraphQL__Fragment__Pagination
48
43
  nodes {
49
- id
50
- altId
51
- actionCategory {
52
- name
53
- value
54
- }
55
- standaloneAction
56
- status
57
- relativeStatus
58
- archived
59
- tags
60
- name
61
- description
62
- assignedTo {
63
- name
64
- email
65
- }
66
- dueDate {
67
- dateTime
68
- timeZone
69
- }
70
- completedAt {
71
- dateTime
72
- timeZone
73
- }
74
- completer {
75
- name
76
- email
77
- }
78
- linkedResources {
79
- page {
80
- name
81
- mouldCounter
82
- }
83
- field {
84
- label
85
- }
86
- }
44
+ ___Ecoportal__API__GraphQL__Fragment__Action
87
45
  }
88
46
  }
89
47
  end
@@ -8,11 +8,9 @@ module Ecoportal
8
8
 
9
9
  def query(path: default_base_path, **kargs, &block)
10
10
  path ||= default_base_path
11
- kargs = self.class.slice_params(kargs)
12
- ap = access_point(path)
11
+ #ap = access_point(path)
13
12
  request(*path, "contractorEntities") do
14
- next client.query(kargs, &basic_block(&block)) if block_given?
15
- client.query(kargs, &basic_block)
13
+ graphql_query(**kargs, &basic_block(&block))
16
14
  end
17
15
  end
18
16
 
@@ -47,13 +45,7 @@ module Ecoportal
47
45
  endCursor
48
46
  }
49
47
  nodes {
50
- id
51
- name
52
- schemaId
53
- active
54
- approved
55
- associatedPeopleIds
56
- leadContractorIds
48
+ ___Ecoportal__API__GraphQL__Fragment__ContractorEntity
57
49
  }
58
50
  }
59
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.3"
3
+ GRAPQL_VERSION = "0.1.5"
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.3
4
+ version: 0.1.5
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-15 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