ecoportal-api-graphql 0.1.10 → 0.1.11

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: 76cdada612c878305f9e858213257fc1a9f92ebc2997ed71295b81e987344cb3
4
- data.tar.gz: 9554e3751ad19aa4de5b66d4d949f8fd77d9e5ad63c15ad2b17c1806e02d5c8b
3
+ metadata.gz: f2fc73626ffb4955b88d20778e32206ad4b989fc47bcc6abbdaf748c035244a6
4
+ data.tar.gz: c00e9f570f81de6520ef738c8cd059dbfb6d80fe18613599d2a6f7ad53556416
5
5
  SHA512:
6
- metadata.gz: d5f0a0fcf7e9e123ec91387f07084e0d92bebe6e5ec4d642a2a1906b382e4eeece58caeac8543938ebb04da22bf67f8eb89082e7062b2b7f990f81674f0dbb5e
7
- data.tar.gz: 8dee0453e5d49178e107bc567ceb93d5150cfd0e2f024a1db3e36e928718f3dece27bdceb2c17a2fe10bb34e6bec62bd217d62ed490f18f3ea2eb9aa92983c08
6
+ metadata.gz: 04477f6f4c8014bccd9f1fc93625f031991e0f0bd979af476ec859f1802832726686a06f1dfa665c9d0ec8762d38eb03aa5bb621a51a28112b513b0b80ef7f37
7
+ data.tar.gz: 249e23c774b1ee031c18d7e53a5be53948c3bf7f5bfffcb2fe4d679a4ab249d81ab59498878a0e2b209720cf6e0b556fef555b0d8dab1bf710be4b2dd243b0d4
data/CHANGELOG.md CHANGED
@@ -1,19 +1,37 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [0.1.10] - 2022-09-xx
4
+ ## [0.1.13] - 2022-11-xx
5
5
 
6
6
  ### Added
7
7
  ### Changed
8
8
  ### Fixed
9
9
 
10
10
  ### ToDo
11
- - Make `GraphQL` default fragments work
12
- - Add update/create operations for `ContractorEntity`
11
+ - Add update operation for `ContractorEntity`
13
12
  - Add currentOrganization.action
14
13
  - Analyse how to "DSL" currentOrganization.action.activities
15
14
  - review `path` tracking
16
15
 
16
+ ## [0.1.12] - 2022-11-xx
17
+
18
+ ### Added
19
+ - `Ecoportal::API::GraphQL::Base::Mutation`
20
+ - Added `createContractorEntity`
21
+
22
+ ### Changed
23
+ - Slight internal refactor of `Ecoportal::API::GraphQL::Base::Query`
24
+ - Upgraded `ecoportal-api-v2` **gem** dependency
25
+
26
+ ## [0.1.11] - 2022-11-02
27
+
28
+ ### Added
29
+ ### Changed
30
+ - **upgraded** `graphlient` gem dependency (support for framents)
31
+ - removed patch in this gem
32
+
33
+ ### Fixed
34
+
17
35
  ## [0.1.10] - 2022-09-29
18
36
 
19
37
  ### Changed
@@ -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.9.2', '< 0.10'
33
- spec.add_dependency 'graphlient', '>= 0.6.0', '< 0.7'
32
+ spec.add_dependency 'ecoportal-api-v2', '>= 0.9.7', '< 0.10'
33
+ spec.add_dependency 'graphlient', '>= 0.7.0', '< 0.8'
34
34
  end
@@ -1 +1 @@
1
- require_relative 'patches/query'
1
+ #require_relative 'patches/query'
@@ -0,0 +1,98 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Base
5
+ class Mutation
6
+ class GenericPayload
7
+ def initialize(*args, **kargs)
8
+ raise "Missuse error. You should define a payload_class for a class that inherits from Mutation class."
9
+ end
10
+ end
11
+
12
+ include Ecoportal::API::Common::GraphQL::ClassHelpers
13
+
14
+ class << self
15
+ # Used to obtain the full `path` in the GraphQL query by using `base_path`
16
+ # @note it is meant for reusability of queries from different end-points
17
+ def field_name(str = nil)
18
+ return @field_name unless str
19
+ @field_name = nil
20
+ @field_name = str.to_s if str
21
+ end
22
+ end
23
+
24
+ class_resolver :payload_class, GenericPayload
25
+ attr_reader :client
26
+ attr_reader :base_path
27
+
28
+ def initialize(client, path: nil, base_path: [])
29
+ @path = path
30
+ @base_path = base_path
31
+ @client = client
32
+ end
33
+
34
+ # Resolves the `path` by using `path` or `base_path` + `class.field_name`.
35
+ def path(field_name = self.class.field_name)
36
+ result = @path
37
+ result ||= default_path if self.respond_to?(:default_path, true)
38
+ result ||= (base_path + [field_name]) if base_path && field_name
39
+ result
40
+ end
41
+
42
+ # Query rely that manages the different blocks.
43
+ # @return [Class] an object of `response_class` with the results hanving from `path`.
44
+ def query(input:, path: self.path, &block)
45
+ request(*path) do
46
+ client.query(input: as_input(input), &basic_block(&block))
47
+ end
48
+ rescue Faraday::ParsingError => e
49
+ puts "Internal Error with these input ('#{input.class}'):"
50
+ pp input
51
+ raise
52
+ end
53
+
54
+ def response_class
55
+ payload_class
56
+ end
57
+
58
+ def access_point(path = [])
59
+ path.last
60
+ end
61
+
62
+ private
63
+
64
+ def basic_block(&block)
65
+ raise "This method should be implemented in the child class #{self.class}"
66
+ end
67
+
68
+ def as_input(value)
69
+ case value
70
+ when Hash
71
+ value
72
+ when Ecoportal::API::GraphQL::Base::Model
73
+ value.as_input
74
+ when Hash
75
+ value = Helpers::Model::HashKeys.keys_to_sym_deep(value)
76
+ Ecoportal::API::Base::Model.as_input(value)
77
+ when Enumerable
78
+ value.map {|v| as_input(v)}
79
+ else
80
+ raise ArgumentError.new("Expecting Hash, GraphQL::Base::Model or Enumerable. Unsupported type '#{value.class}'.")
81
+ end
82
+ end
83
+
84
+ def request(*path)
85
+ response = yield
86
+ wrap_response(response, path)
87
+ end
88
+
89
+ def wrap_response(response, path = [])
90
+ raise "Complete failure on request. Path: #{path}" unless res = response.to_h.dig(*path.dup.unshift("data"))
91
+ data = Ecoportal::API::Common::GraphQL::HashHelpers.deep_dup(res)
92
+ response_class.new(data)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -39,7 +39,6 @@ module Ecoportal
39
39
 
40
40
  class_resolver :item_class, GenericItem
41
41
  attr_reader :client
42
-
43
42
  attr_reader :base_path
44
43
 
45
44
  def initialize(client, path: nil, base_path: nil)
@@ -57,7 +56,7 @@ module Ecoportal
57
56
  end
58
57
 
59
58
  # Query rely that manages the different blocks.
60
- # @return [Class] an object of `response_class` with the results hanving from `path`.
59
+ # @return [Class] an object of `response_class` with the results hanging from `path`.
61
60
  def query(path: self.path, **kargs, &block)
62
61
  graphql_query(path: path, **kargs, &basic_block(&block))
63
62
  end
@@ -72,6 +71,10 @@ module Ecoportal
72
71
 
73
72
  private
74
73
 
74
+ def basic_block
75
+ raise "This method should be implemented in the child class #{self.class}"
76
+ end
77
+
75
78
  def graphql_query(path: self.path, **kargs, &block)
76
79
  query_params = self.class.slice_params(kargs)
77
80
  request(*path) do
@@ -89,7 +92,7 @@ module Ecoportal
89
92
  end
90
93
 
91
94
  def wrap_response(response, path = [])
92
- raise "Complete failure on request. Path: #{path}" unless res = response.to_h.dig("data", *path)
95
+ raise "Complete failure on request. Path: #{path}" unless res = response.to_h.dig(*path.dup.unshift("data"))
93
96
  data = Ecoportal::API::Common::GraphQL::HashHelpers.deep_dup(res)
94
97
  response_class.new(data)
95
98
  end
@@ -12,6 +12,7 @@ require 'ecoportal/api/graphql/base/date_time'
12
12
  require 'ecoportal/api/graphql/base/id_diff_input'
13
13
  require 'ecoportal/api/graphql/base/page_info'
14
14
  require 'ecoportal/api/graphql/base/query'
15
+ require 'ecoportal/api/graphql/base/mutation'
15
16
  require 'ecoportal/api/graphql/base/connection'
16
17
  require 'ecoportal/api/graphql/base/query_array'
17
18
  require 'ecoportal/api/graphql/base/query_connection'
@@ -0,0 +1,38 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Mutation
5
+ class CreateContractorEntity < Ecoportal::API::GraphQL::Base::Mutation
6
+ field_name :createContractorEntity
7
+
8
+ #class_resolver :item_class, Ecoportal::API::GraphQL::Model::ContractorEntity
9
+ class_resolver :payload_class, Ecoportal::API::GraphQL::Payload::CreateContractorEntity
10
+
11
+ private
12
+
13
+ def basic_block(&block)
14
+ payload_block = block || default_payload_block
15
+ Proc.new {
16
+ mutation(input: :CreateContractorEntityInput!) {
17
+ createContractorEntity(input: :input, &payload_block)
18
+ }
19
+ }
20
+ end
21
+
22
+ def default_payload_block
23
+ Proc.new {
24
+ clientMutationId
25
+ errors {
26
+ details
27
+ fullMessages
28
+ }
29
+ item {
30
+ ___Fragment__ContractorEntity
31
+ }
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Mutation
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'ecoportal/api/graphql/mutation/create_contractor_entity'
@@ -25,6 +25,17 @@ module Ecoportal
25
25
  def currentOrganization
26
26
  currentOrganizationClass
27
27
  end
28
+
29
+ def createContractorEntity(input:, &block)
30
+ createContractorEntityMutation.query(input: input, &block)
31
+ end
32
+
33
+ private
34
+
35
+ def createContractorEntityMutation
36
+ Ecoportal::API::GraphQL::Mutation::CreateContractorEntity.new(client)
37
+ end
38
+
28
39
  end
29
40
  end
30
41
  end
@@ -37,3 +48,4 @@ require 'ecoportal/api/graphql/payload'
37
48
  require 'ecoportal/api/graphql/input'
38
49
  require 'ecoportal/api/graphql/fragment'
39
50
  require 'ecoportal/api/graphql/query'
51
+ require 'ecoportal/api/graphql/mutation'
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GRAPQL_VERSION = "0.1.10"
3
+ GRAPQL_VERSION = "0.1.11"
4
4
  end
5
5
  end
@@ -0,0 +1,19 @@
1
+ require_relative 'local_libs'
2
+
3
+ api = Ecoportal::API::GraphQL.new
4
+ response = api.createContractorEntity(input: {
5
+ name: "Caras Galathon",
6
+ active: true,
7
+ approved: true,
8
+ associatedPeopleIds: [
9
+ "5adfbef76fb80400047535b3"
10
+ ],
11
+ leadContractorIds: [
12
+ "5adfbef76fb80400047535b3"
13
+ ],
14
+ clientMutationId: ""
15
+ })
16
+
17
+ if response.success? && entity = response.item
18
+ puts "Created contractor entity '#{entity.name}' (approved? #{entity.approved})"
19
+ 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.10
4
+ version: 0.1.11
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-29 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,7 +130,7 @@ dependencies:
130
130
  requirements:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
- version: 0.9.2
133
+ version: 0.9.7
134
134
  - - "<"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0.10'
@@ -140,7 +140,7 @@ dependencies:
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: 0.9.2
143
+ version: 0.9.7
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0.10'
@@ -150,20 +150,20 @@ dependencies:
150
150
  requirements:
151
151
  - - ">="
152
152
  - !ruby/object:Gem::Version
153
- version: 0.6.0
153
+ version: 0.7.0
154
154
  - - "<"
155
155
  - !ruby/object:Gem::Version
156
- version: '0.7'
156
+ version: '0.8'
157
157
  type: :runtime
158
158
  prerelease: false
159
159
  version_requirements: !ruby/object:Gem::Requirement
160
160
  requirements:
161
161
  - - ">="
162
162
  - !ruby/object:Gem::Version
163
- version: 0.6.0
163
+ version: 0.7.0
164
164
  - - "<"
165
165
  - !ruby/object:Gem::Version
166
- version: '0.7'
166
+ version: '0.8'
167
167
  description:
168
168
  email:
169
169
  - oscar@ecoportal.co.nz
@@ -195,7 +195,6 @@ files:
195
195
  - lib/ecoportal/api/common/graphql/hash_helpers.rb
196
196
  - lib/ecoportal/api/common/graphql/http_client.rb
197
197
  - lib/ecoportal/api/common/graphql/patches.rb
198
- - lib/ecoportal/api/common/graphql/patches/query.rb
199
198
  - lib/ecoportal/api/common/graphql/query_integration.rb
200
199
  - lib/ecoportal/api/graphql.rb
201
200
  - lib/ecoportal/api/graphql/base.rb
@@ -209,6 +208,7 @@ files:
209
208
  - lib/ecoportal/api/graphql/base/file_container.rb
210
209
  - lib/ecoportal/api/graphql/base/id_diff_input.rb
211
210
  - lib/ecoportal/api/graphql/base/model.rb
211
+ - lib/ecoportal/api/graphql/base/mutation.rb
212
212
  - lib/ecoportal/api/graphql/base/organization.rb
213
213
  - lib/ecoportal/api/graphql/base/page.rb
214
214
  - lib/ecoportal/api/graphql/base/page_info.rb
@@ -253,6 +253,8 @@ files:
253
253
  - lib/ecoportal/api/graphql/model/tag_tree.rb
254
254
  - lib/ecoportal/api/graphql/model/tag_tree_node.rb
255
255
  - lib/ecoportal/api/graphql/model/user.rb
256
+ - lib/ecoportal/api/graphql/mutation.rb
257
+ - lib/ecoportal/api/graphql/mutation/create_contractor_entity.rb
256
258
  - lib/ecoportal/api/graphql/payload.rb
257
259
  - lib/ecoportal/api/graphql/payload/create_contractor_entity.rb
258
260
  - lib/ecoportal/api/graphql/payload/destroy_contractor_entity.rb
@@ -265,6 +267,7 @@ files:
265
267
  - lib/ecoportal/api/graphql_version.rb
266
268
  - tests/actions_get.rb
267
269
  - tests/contractor_entities_get.rb
270
+ - tests/create_contractor_entity.rb
268
271
  - tests/local_libs.rb
269
272
  - tests/tagtree_get.rb
270
273
  - tests/tagtrees_get.rb
@@ -1,49 +0,0 @@
1
- module Graphlient
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
-
12
- private
13
-
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
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?('___')
31
-
32
- # add field
33
- @query_str << "\n#{indent}#{node}"
34
- # add filter
35
- hash_arguments = hash_arg(args)
36
- @query_str << "(#{args_str(hash_arguments, arg_processor: arg_processor)})" if hash_arguments
37
-
38
- if block_given?
39
- @indents += 1
40
- @query_str << '{'
41
- evaluate(&block)
42
- @query_str << '}'
43
- @indents -= 1
44
- end
45
-
46
- @query_str << "\n#{indent}"
47
- end
48
- end
49
- end