ecoportal-api-graphql 0.4.3 → 0.4.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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -4
  3. data/Rakefile +10 -10
  4. data/ecoportal-api-graphql.gemspec +22 -19
  5. data/lib/ecoportal/api/common/graphql/class_helpers.rb +6 -3
  6. data/lib/ecoportal/api/common/graphql/hash_helpers.rb +60 -30
  7. data/lib/ecoportal/api/common/graphql/http_client.rb +6 -12
  8. data/lib/ecoportal/api/common/graphql/model/as_input.rb +40 -0
  9. data/lib/ecoportal/api/common/graphql/model/diffable/hash_diff.rb +60 -0
  10. data/lib/ecoportal/api/common/graphql/model/diffable.rb +32 -0
  11. data/lib/ecoportal/api/common/graphql/model.rb +17 -0
  12. data/lib/ecoportal/api/common/graphql/query_integration.rb +5 -2
  13. data/lib/ecoportal/api/common/graphql.rb +1 -2
  14. data/lib/ecoportal/api/graphql/base/action.rb +3 -1
  15. data/lib/ecoportal/api/graphql/base/action_category.rb +3 -1
  16. data/lib/ecoportal/api/graphql/base/contractor_entity.rb +2 -0
  17. data/lib/ecoportal/api/graphql/base/location_classification_type.rb +1 -1
  18. data/lib/ecoportal/api/graphql/base/location_node.rb +2 -0
  19. data/lib/ecoportal/api/graphql/base/location_structure.rb +1 -0
  20. data/lib/ecoportal/api/graphql/base/model.rb +1 -21
  21. data/lib/ecoportal/api/graphql/base/organization.rb +2 -0
  22. data/lib/ecoportal/api/graphql/base/page.rb +2 -0
  23. data/lib/ecoportal/api/graphql/base/person_member.rb +2 -0
  24. data/lib/ecoportal/api/graphql/builder/action.rb +8 -0
  25. data/lib/ecoportal/api/graphql/connection/action_category.rb +11 -0
  26. data/lib/ecoportal/api/graphql/connection.rb +1 -0
  27. data/lib/ecoportal/api/graphql/error/locations_error.rb +2 -0
  28. data/lib/ecoportal/api/graphql/error/locations_validation_error.rb +2 -0
  29. data/lib/ecoportal/api/graphql/error/validation_errors.rb +1 -0
  30. data/lib/ecoportal/api/graphql/fragment/action.rb +5 -1
  31. data/lib/ecoportal/api/graphql/fragment/action_category.rb +17 -0
  32. data/lib/ecoportal/api/graphql/fragment.rb +3 -0
  33. data/lib/ecoportal/api/graphql/helpers/locations_tree.rb +10 -10
  34. data/lib/ecoportal/api/graphql/input/action/create.rb +13 -0
  35. data/lib/ecoportal/api/graphql/input/action.rb +2 -1
  36. data/lib/ecoportal/api/graphql/logic/base_query.rb +5 -2
  37. data/lib/ecoportal/api/graphql/logic/mutation.rb +3 -5
  38. data/lib/ecoportal/api/graphql/logic/payload.rb +2 -0
  39. data/lib/ecoportal/api/graphql/logic/query.rb +4 -1
  40. data/lib/ecoportal/api/graphql/logic/query_array.rb +1 -0
  41. data/lib/ecoportal/api/graphql/logic/query_connection.rb +2 -0
  42. data/lib/ecoportal/api/graphql/model/account.rb +2 -0
  43. data/lib/ecoportal/api/graphql/model/action.rb +1 -0
  44. data/lib/ecoportal/api/graphql/model/contractor_entity.rb +2 -2
  45. data/lib/ecoportal/api/graphql/model/location_node.rb +1 -1
  46. data/lib/ecoportal/api/graphql/model/organization.rb +1 -0
  47. data/lib/ecoportal/api/graphql/model/user.rb +2 -0
  48. data/lib/ecoportal/api/graphql/mutation/action/create.rb +40 -0
  49. data/lib/ecoportal/api/graphql/mutation/action.rb +2 -1
  50. data/lib/ecoportal/api/graphql/payload/action/create.rb +13 -0
  51. data/lib/ecoportal/api/graphql/payload/action.rb +2 -1
  52. data/lib/ecoportal/api/graphql/payload/location_structure/apply_commands.rb +2 -0
  53. data/lib/ecoportal/api/graphql/payload/location_structure/command_execution_result.rb +2 -0
  54. data/lib/ecoportal/api/graphql/query/action_categories.rb +52 -0
  55. data/lib/ecoportal/api/graphql/query/location_structures.rb +5 -4
  56. data/lib/ecoportal/api/graphql/query.rb +1 -0
  57. data/lib/ecoportal/api/graphql_version.rb +1 -1
  58. metadata +36 -27
  59. data/lib/ecoportal/api/common/graphql/doc_helpers.rb +0 -10
@@ -17,6 +17,10 @@ module Ecoportal
17
17
  updateMutation.query(**kargs, &block)
18
18
  end
19
19
 
20
+ def create(**kargs, &block)
21
+ createMutation.query(**kargs, &block)
22
+ end
23
+
20
24
  private
21
25
 
22
26
  def archiveMutation
@@ -26,6 +30,10 @@ module Ecoportal
26
30
  def updateMutation
27
31
  Ecoportal::API::GraphQL::Mutation::Action::Update.new(client)
28
32
  end
33
+
34
+ def createMutation
35
+ Ecoportal::API::GraphQL::Mutation::Action::Create.new(client)
36
+ end
29
37
  end
30
38
  end
31
39
  end
@@ -0,0 +1,11 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Connection
5
+ class ActionCategory < Ecoportal::API::GraphQL::Logic::Connection
6
+ class_resolver :node_class, Ecoportal::API::GraphQL::Base::ActionCategory
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -9,4 +9,5 @@ end
9
9
 
10
10
  require 'ecoportal/api/graphql/connection/person_member'
11
11
  require 'ecoportal/api/graphql/connection/contractor_entity'
12
+ require 'ecoportal/api/graphql/connection/action_category'
12
13
  require 'ecoportal/api/graphql/connection/action'
@@ -3,6 +3,8 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Error
5
5
  class LocationsError < Ecoportal::API::GraphQL::Base::Model
6
+ read_only!
7
+
6
8
  passthrough :message, :conflictingIds
7
9
  passthrough :type
8
10
  embeds_many :validationErrors, klass: Ecoportal::API::GraphQL::Error::LocationsValidationError
@@ -3,6 +3,8 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Error
5
5
  class LocationsValidationError < Ecoportal::API::GraphQL::Base::Model
6
+ read_only!
7
+
6
8
  passthrough :error, :message, :property
7
9
  end
8
10
  end
@@ -14,6 +14,7 @@ module Ecoportal
14
14
 
15
15
  def each(&block)
16
16
  return to_enum(:each) unless block
17
+
17
18
  fullMessages.each(&block)
18
19
  end
19
20
  end
@@ -15,7 +15,11 @@ module Ecoportal
15
15
  status
16
16
  relativeStatus
17
17
  archived
18
- tags
18
+ locations {
19
+ id
20
+ name
21
+ objectId
22
+ }
19
23
  name
20
24
  description
21
25
  assignedTo {
@@ -0,0 +1,17 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ class Fragment
5
+ fragment :ActionCategory, <<~GRAPHQL
6
+ fragment on Category {
7
+ id
8
+ name
9
+ value
10
+ archived
11
+ weight
12
+ }
13
+ GRAPHQL
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,6 +2,7 @@
2
2
  module Fragment
3
3
  include Ecoportal::API::Common::GraphQL::ClassHelpers
4
4
  end
5
+
5
6
  # Class to define/parse fragments
6
7
  module Ecoportal
7
8
  module API
@@ -28,6 +29,7 @@ module Ecoportal
28
29
 
29
30
  def define(sym, heredoc, namespace: ::Fragment)
30
31
  namespace.send(:remove_const, sym) if namespace.const_defined?(sym)
32
+
31
33
  client.parse(heredoc).tap do |fragment|
32
34
  without_warnings do
33
35
  namespace.const_set(sym, fragment)
@@ -59,5 +61,6 @@ end
59
61
 
60
62
  require 'ecoportal/api/graphql/fragment/pagination'
61
63
  require 'ecoportal/api/graphql/fragment/location_node'
64
+ require 'ecoportal/api/graphql/fragment/action_category'
62
65
  require 'ecoportal/api/graphql/fragment/action'
63
66
  require 'ecoportal/api/graphql/fragment/contractor_entity'
@@ -3,7 +3,7 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Helpers
5
5
  module LocationsTree
6
- RELEVANT_NODES_COUNT = 1000
6
+ RELEVANT_NODES_COUNT = 1_000
7
7
 
8
8
  def treeify(nodes)
9
9
  parents = nodes.each_with_object({}) do |node, out|
@@ -21,15 +21,15 @@ module Ecoportal
21
21
  class_names = class_types.map(&:name)
22
22
 
23
23
  results << {
24
- "id" => child.id,
25
- "name" => child.name,
26
- "weight" => child.weight,
27
- "parent_id" => node_id,
28
- "archived" => child.archived,
29
- "archived_token" => child.archivedToken,
30
- "classifications" => class_ids,
31
- "classification_names" => class_names,
32
- "nodes" => get_children(child.id, parents).compact
24
+ 'id' => child.id,
25
+ 'name' => child.name,
26
+ 'weight' => child.weight,
27
+ 'parent_id' => node_id,
28
+ 'archived' => child.archived,
29
+ 'archived_token' => child.archivedToken,
30
+ 'classifications' => class_ids,
31
+ 'classification_names' => class_names,
32
+ 'nodes' => get_children(child.id, parents).compact
33
33
  }
34
34
  end
35
35
  end
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Input
5
+ module Action
6
+ class Create < Ecoportal::API::GraphQL::Base::Action
7
+ passthrough :clientMutationId
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,5 +9,6 @@ module Ecoportal
9
9
  end
10
10
  end
11
11
 
12
- require_relative 'action/archive'
12
+ require_relative 'action/create'
13
13
  require_relative 'action/update'
14
+ require_relative 'action/archive'
@@ -14,6 +14,7 @@ module Ecoportal
14
14
  def accepted_params(*keys, default: :unused)
15
15
  @accepted_params ||= []
16
16
  return @accepted_params if keys.empty?
17
+
17
18
  keys.map(&:to_sym).uniq.each do |key|
18
19
  @accepted_params |= [key]
19
20
  param_defaults[key] = default unless default == :unused
@@ -36,12 +37,14 @@ module Ecoportal
36
37
  # @note it is meant for reusability of queries from different end-points
37
38
  def field_name(str = nil)
38
39
  return @field_name unless str
40
+
39
41
  @field_name = nil
40
42
  @field_name = str.to_s if str
41
43
  end
42
44
 
43
45
  def base_path(path = :unused)
44
46
  return @base_path if path == :unused
47
+
45
48
  path ||= []
46
49
  path = path.to_s.split('.') if path.is_a?(String)
47
50
  path = path.map(&:to_s).compact
@@ -51,8 +54,7 @@ module Ecoportal
51
54
 
52
55
  include Ecoportal::API::Common::Concerns::Benchmarkable
53
56
 
54
- attr_reader :client
55
- attr_reader :base_path
57
+ attr_reader :client, :base_path
56
58
 
57
59
  def initialize(client, path: nil, base_path: self.class.base_path)
58
60
  @path = path
@@ -94,6 +96,7 @@ module Ecoportal
94
96
  def graphql_query(path: self.path, raw_response: {}, **kargs, &block)
95
97
  default_params = self.class.param_defaults.dup
96
98
  query_params = self.class.slice_params(default_params.merge(kargs))
99
+
97
100
  request(*path) do
98
101
  raw_response[:data] = client.query(query_params, &block)
99
102
  end
@@ -5,13 +5,13 @@ module Ecoportal
5
5
  class Mutation < Ecoportal::API::GraphQL::Logic::BaseQuery
6
6
  class GenericPayload
7
7
  def initialize(*_args, **_kargs)
8
- raise "Missuse error. You should define a payload_class for a class that inherits from Mutation class."
8
+ raise 'Missuse error. You should define a payload_class for a class that inherits from Mutation class.'
9
9
  end
10
10
  end
11
11
 
12
12
  class GenericInput
13
13
  def initialize(*_args, **_kargs)
14
- raise "Missuse error. You should define a input_class for a class that inherits from Mutation class."
14
+ raise 'Missuse error. You should define a input_class for a class that inherits from Mutation class.'
15
15
  end
16
16
  end
17
17
 
@@ -38,12 +38,10 @@ module Ecoportal
38
38
 
39
39
  def as_input(value)
40
40
  case value
41
- when input_class
41
+ when input_class, Ecoportal::API::GraphQL::Base::Model
42
42
  value.as_input
43
43
  when Hash
44
44
  value
45
- when Ecoportal::API::GraphQL::Base::Model
46
- value.as_input
47
45
  # when Hash
48
46
  # value = Helpers::Model::HashKeys.keys_to_sym_deep(value)
49
47
  # Ecoportal::API::Base::Model.as_input(value)
@@ -9,6 +9,8 @@ module Ecoportal
9
9
  end
10
10
  end
11
11
 
12
+ read_only!
13
+
12
14
  passthrough :clientMutationId
13
15
 
14
16
  class_resolver :item_class, GenericItem
@@ -5,7 +5,10 @@ module Ecoportal
5
5
  class Query < Ecoportal::API::GraphQL::Logic::BaseQuery
6
6
  class GenericItem
7
7
  def initialize(*_args, **_kargs)
8
- raise "Missuse error. You should define a item_class for a class that inherits from Query class."
8
+ msg = "Missuse error. "
9
+ msg << "You should define a item_class for a class that "
10
+ msg << "inherits from Query class."
11
+ raise msg
9
12
  end
10
13
  end
11
14
  class_resolver :item_class, GenericItem
@@ -14,6 +14,7 @@ module Ecoportal
14
14
 
15
15
  def response_class
16
16
  return array_class if respond_to?(:array_class)
17
+
17
18
  @response_class ||= self.class.new_class(
18
19
  item_class,
19
20
  inherits: Ecoportal::API::Common::Content::CollectionModel
@@ -8,6 +8,7 @@ module Ecoportal
8
8
 
9
9
  def each(connection_block: nil, **kargs, &block)
10
10
  return to_enum(:each, **kargs, connection_block: connection_block) unless block
11
+
11
12
  cursor = nil
12
13
  loop do
13
14
  kargs.update(after: cursor) if cursor
@@ -21,6 +22,7 @@ module Ecoportal
21
22
 
22
23
  def response_class
23
24
  return connection_class if respond_to?(:connection_class)
25
+
24
26
  @response_class ||= self.class.new_class(
25
27
  item_class,
26
28
  inherits: Ecoportal::API::GraphQL::Logic::Connection,
@@ -3,6 +3,8 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Model
5
5
  class Account < Ecoportal::API::GraphQL::Base::Model
6
+ root!
7
+
6
8
  passkey :id
7
9
  passthrough :default_tag
8
10
  passboolean :active
@@ -12,6 +12,7 @@ module Ecoportal
12
12
  embeds_one :completer, klass: Model::PersonMember
13
13
  embeds_many :fileContainers, klass: Model::FileContainer
14
14
  embeds_many :linkedResources, klass: Model::Resource
15
+ embeds_many :locations, klass: Model::LocationNode
15
16
  #embeds_many :activities, klass: GraphQL::Model::Action::Activity
16
17
  #embeds_one :recurrence, klass: GraphQL::Model::Action::Recurrence
17
18
  end
@@ -3,8 +3,8 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Model
5
5
  class ContractorEntity < Ecoportal::API::GraphQL::Base::ContractorEntity
6
- embeds_one :associatedPeople, klass: "Ecoportal::API::GraphQL::Connections::PersonMemberConnection"
7
- embeds_many :leadContractors, enum_class: "Ecoportal::API::GraphQL::Model::PersonMember"
6
+ embeds_one :associatedPeople, read_only: true, klass: "Ecoportal::API::GraphQL::Connections::PersonMemberConnection"
7
+ embeds_many :leadContractors, read_only: true, klass: "Ecoportal::API::GraphQL::Model::PersonMember"
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module Ecoportal
4
4
  module Model
5
5
  class LocationNode < Ecoportal::API::GraphQL::Base::LocationNode
6
6
  embeds_one :parent, klass: Model::LocationNode, nullable: true
7
- embeds_many :ancestors, klass: Model::LocationNode
7
+ embeds_many :ancestors, read_only: true, klass: Model::LocationNode
8
8
 
9
9
  def parentId
10
10
  parent&.id
@@ -16,6 +16,7 @@ module Ecoportal
16
16
  query :locationStructures, subpath: "locations", query_klass: "Ecoportal::API::GraphQL::Query::LocationStructures"
17
17
  query :contractorEntities, query_klass: "Ecoportal::API::GraphQL::Query::ContractorEntities"
18
18
  #contractorEntity,
19
+ query :actionCategories, query_klass: "Ecoportal::API::GraphQL::Query::ActionCategories"
19
20
  query :action, query_klass: "Ecoportal::API::GraphQL::Query::Action"
20
21
  query :actions, query_klass: "Ecoportal::API::GraphQL::Query::Actions"
21
22
  query :archiveAction, query_klass: "Ecoportal::API::GraphQL::Mutation::Action::Archive"
@@ -3,6 +3,8 @@ module Ecoportal
3
3
  class GraphQL
4
4
  module Model
5
5
  class User < Ecoportal::API::GraphQL::Base::Model
6
+ root!
7
+
6
8
  passkey :id
7
9
  passthrough :email, :name
8
10
  end
@@ -0,0 +1,40 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Mutation
5
+ module Action
6
+ class Create < Ecoportal::API::GraphQL::Logic::Mutation
7
+ field_name :createAction
8
+
9
+ class_resolver :payload_class, Ecoportal::API::GraphQL::Payload::Action::Create
10
+ class_resolver :input_class, Ecoportal::API::GraphQL::Input::Action::Create
11
+
12
+ private
13
+
14
+ def basic_block(&block)
15
+ payload_block = block || default_payload_block
16
+ proc {
17
+ mutation(input: :CreateActionInput!) {
18
+ createAction(input: :input, &payload_block)
19
+ }
20
+ }
21
+ end
22
+
23
+ def default_payload_block
24
+ proc {
25
+ clientMutationId
26
+ errors {
27
+ details
28
+ fullMessages
29
+ }
30
+ item {
31
+ ___Fragment__Action
32
+ }
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -9,5 +9,6 @@ module Ecoportal
9
9
  end
10
10
  end
11
11
 
12
- require_relative 'action/archive'
12
+ require_relative 'action/create'
13
13
  require_relative 'action/update'
14
+ require_relative 'action/archive'
@@ -0,0 +1,13 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Payload
5
+ module Action
6
+ class Create < Ecoportal::API::GraphQL::Logic::Payload
7
+ class_resolver :item_class, "Ecoportal::API::GraphQL::Model::Action"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,5 +9,6 @@ module Ecoportal
9
9
  end
10
10
  end
11
11
 
12
- require_relative 'action/archive'
12
+ require_relative 'action/create'
13
13
  require_relative 'action/update'
14
+ require_relative 'action/archive'
@@ -4,6 +4,8 @@ module Ecoportal
4
4
  module Payload
5
5
  module LocationStructure
6
6
  class ApplyCommands < Ecoportal::API::GraphQL::Base::Model
7
+ read_only!
8
+
7
9
  passthrough :clientMutationId
8
10
  embeds_one :structure, klass: Ecoportal::API::GraphQL::Model::LocationStructure
9
11
  embeds_one :errors, klass: Ecoportal::API::GraphQL::Error::ValidationErrors, nullable: true
@@ -4,6 +4,8 @@ module Ecoportal
4
4
  module Payload
5
5
  module LocationStructure
6
6
  class CommandExecutionResult < Ecoportal::API::GraphQL::Base::Model
7
+ read_only!
8
+
7
9
  embeds_one :command, klass: Ecoportal::API::GraphQL::Payload::LocationStructure::CommandInterface
8
10
  embeds_one :error, nullable: true, klass: Ecoportal::API::GraphQL::Error::LocationsError
9
11
  passboolean :ok
@@ -0,0 +1,52 @@
1
+ module Ecoportal
2
+ module API
3
+ class GraphQL
4
+ module Query
5
+ class ActionCategories < Ecoportal::API::GraphQL::Logic::QueryConnection
6
+ field_name :actionCategories
7
+
8
+ class_resolver :item_class, Ecoportal::API::GraphQL::Base::ActionCategory
9
+ class_resolver :connection_class, Ecoportal::API::GraphQL::Connection::ActionCategory
10
+
11
+ private
12
+
13
+ def basic_block(&block)
14
+ connection_block = block || default_connection_block
15
+ proc {
16
+ query(
17
+ searchConf: :Search,
18
+ after: :string,
19
+ before: :string,
20
+ first: :int,
21
+ last: :int
22
+ ) {
23
+ currentOrganization {
24
+ actionCategories(
25
+ searchConf: :searchConf,
26
+ after: :after,
27
+ before: :before,
28
+ first: :first,
29
+ last: :last,
30
+ &connection_block
31
+ )
32
+ }
33
+ }
34
+ }
35
+ end
36
+
37
+ def default_connection_block
38
+ proc {
39
+ totalCount
40
+ pageInfo {
41
+ endCursor
42
+ }
43
+ nodes {
44
+ ___Ecoportal__API__GraphQL__Fragment__ActionCategory
45
+ }
46
+ }
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -15,14 +15,15 @@ module Ecoportal
15
15
  def basic_block(&block)
16
16
  final_block = block || default_query_block
17
17
  proc {
18
- query(includeArchived: :boolean,
19
- includeUnpublished: :boolean,
20
- includeArchivedNodes: :boolean
18
+ query(
19
+ includeArchived: :boolean,
20
+ includeUnpublished: :boolean,
21
+ includeArchivedNodes: :boolean
21
22
  ) {
22
23
  currentOrganization {
23
24
  locations {
24
25
  structures(
25
- includeArchived: :includeArchived,
26
+ includeArchived: :includeArchived,
26
27
  includeUnpublished: :includeUnpublished,
27
28
  &final_block
28
29
  )
@@ -10,6 +10,7 @@ end
10
10
  require 'ecoportal/api/graphql/query/location_classifications'
11
11
  require 'ecoportal/api/graphql/query/location_structure'
12
12
  require 'ecoportal/api/graphql/query/location_structures'
13
+ require 'ecoportal/api/graphql/query/action_categories'
13
14
  require 'ecoportal/api/graphql/query/action'
14
15
  require 'ecoportal/api/graphql/query/actions'
15
16
  require 'ecoportal/api/graphql/query/contractor_entities'
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- GRAPQL_VERSION = '0.4.3'.freeze
3
+ GRAPQL_VERSION = '0.4.5'.freeze
4
4
  end
5
5
  end