graphiti-activegraph 1.3.0 → 1.3.2
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 +4 -4
- data/.github/workflows/specs.yml +58 -51
- data/.gitignore +59 -59
- data/.hound.yml +4 -0
- data/.rspec +1 -1
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +58 -50
- data/CHANGELOG_PRE_1.0.0.md +70 -70
- data/Gemfile +3 -3
- data/LICENSE.txt +21 -21
- data/README.md +130 -123
- data/docs/deserializer.md +40 -0
- data/graphiti-activegraph.gemspec +34 -32
- data/lib/graphiti/active_graph/adapters/active_graph/function_sideload.rb +7 -7
- data/lib/graphiti/active_graph/adapters/active_graph/has_many_sideload.rb +7 -7
- data/lib/graphiti/active_graph/adapters/active_graph/has_one_sideload.rb +7 -7
- data/lib/graphiti/active_graph/adapters/active_graph/polymorphic_belongs_to.rb +11 -11
- data/lib/graphiti/active_graph/adapters/active_graph/sideload.rb +26 -26
- data/lib/graphiti/active_graph/adapters/active_graph.rb +183 -183
- data/lib/graphiti/active_graph/concerns/path_relationships.rb +44 -44
- data/lib/graphiti/active_graph/concerns/relationships.rb +15 -0
- data/lib/graphiti/active_graph/deserializer.rb +138 -141
- data/lib/graphiti/active_graph/extensions/context.rb +17 -17
- data/lib/graphiti/active_graph/extensions/grouping/params.rb +101 -52
- data/lib/graphiti/active_graph/extensions/query_dsl/performer.rb +38 -0
- data/lib/graphiti/active_graph/extensions/query_dsl/query_generator.rb +20 -0
- data/lib/graphiti/active_graph/extensions/query_params.rb +27 -27
- data/lib/graphiti/active_graph/extensions/resources/authorizationable.rb +29 -29
- data/lib/graphiti/active_graph/extensions/resources/payload_combinable.rb +24 -24
- data/lib/graphiti/active_graph/extensions/resources/preloadable.rb +19 -19
- data/lib/graphiti/active_graph/extensions/resources/rel.rb +19 -19
- data/lib/graphiti/active_graph/jsonapi_ext/include_directive.rb +66 -66
- data/lib/graphiti/active_graph/jsonapi_ext/serializable/resource_ext.rb +8 -8
- data/lib/graphiti/active_graph/query.rb +76 -76
- data/lib/graphiti/active_graph/request_validators/validator.rb +9 -9
- data/lib/graphiti/active_graph/resource.rb +103 -103
- data/lib/graphiti/active_graph/resource_proxy.rb +86 -86
- data/lib/graphiti/active_graph/resources/interface.rb +14 -14
- data/lib/graphiti/active_graph/resources/persistence.rb +25 -25
- data/lib/graphiti/active_graph/runner.rb +39 -39
- data/lib/graphiti/active_graph/scope.rb +28 -28
- data/lib/graphiti/active_graph/scoping/association_eager_load.rb +34 -34
- data/lib/graphiti/active_graph/scoping/filter.rb +49 -40
- data/lib/graphiti/active_graph/scoping/filterable.rb +12 -12
- data/lib/graphiti/active_graph/scoping/include.rb +48 -48
- data/lib/graphiti/active_graph/scoping/internal/extra_field_normalizer.rb +76 -76
- data/lib/graphiti/active_graph/scoping/internal/include_normalizer.rb +82 -82
- data/lib/graphiti/active_graph/scoping/internal/path_descriptor.rb +94 -94
- data/lib/graphiti/active_graph/scoping/internal/sort_normalizer.rb +54 -54
- data/lib/graphiti/active_graph/scoping/internal/sorting_aliases.rb +35 -35
- data/lib/graphiti/active_graph/scoping/internal/sparse_fields_eagerloading.rb +28 -28
- data/lib/graphiti/active_graph/serializer.rb +15 -15
- data/lib/graphiti/active_graph/sideload_resolve.rb +119 -119
- data/lib/graphiti/active_graph/util/parsers/rel_chain.rb +27 -27
- data/lib/graphiti/active_graph/util/relationship_payload.rb +33 -33
- data/lib/graphiti/active_graph/util/serializer_attribute.rb +17 -17
- data/lib/graphiti/active_graph/util/serializer_relationship.rb +28 -28
- data/lib/graphiti/active_graph/util/transformers/relation_param.rb +56 -56
- data/lib/graphiti/active_graph/version.rb +5 -5
- data/lib/graphiti/sidepost_configuration.rb +9 -9
- data/lib/graphiti-activegraph.rb +43 -43
- metadata +37 -3
|
@@ -1,141 +1,138 @@
|
|
|
1
|
-
module Graphiti::ActiveGraph
|
|
2
|
-
class Deserializer < Graphiti::Deserializer
|
|
3
|
-
include Concerns::PathRelationships
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@
|
|
11
|
-
@
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@
|
|
24
|
-
@
|
|
25
|
-
@
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
map =
|
|
93
|
-
map
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
#
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
1
|
+
module Graphiti::ActiveGraph
|
|
2
|
+
class Deserializer < Graphiti::Deserializer
|
|
3
|
+
include Concerns::PathRelationships
|
|
4
|
+
include Concerns::Relationships
|
|
5
|
+
|
|
6
|
+
class Conflict < StandardError
|
|
7
|
+
attr_reader :key, :path_value, :body_value
|
|
8
|
+
|
|
9
|
+
def initialize(key, path_value, body_value)
|
|
10
|
+
@key = key
|
|
11
|
+
@path_value = path_value
|
|
12
|
+
@body_value = body_value
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def message
|
|
16
|
+
"Path parameter #{key} with value '#{path_value}' conflicts with payload value '#{body_value}'"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def initialize(payload, env = nil, model = nil, parent_map = nil)
|
|
21
|
+
super(payload)
|
|
22
|
+
|
|
23
|
+
@params = payload
|
|
24
|
+
@model = model
|
|
25
|
+
@parent_map = parent_map || {}
|
|
26
|
+
@env = env
|
|
27
|
+
|
|
28
|
+
return unless data.blank? && env && parsable_content?
|
|
29
|
+
|
|
30
|
+
raise ArgumentError, "JSON API payload must contain the 'data' key"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def process_relationship_datum(datum)
|
|
34
|
+
{
|
|
35
|
+
meta: {
|
|
36
|
+
jsonapi_type: datum[:type],
|
|
37
|
+
temp_id: datum[:'temp-id'],
|
|
38
|
+
method: datum[:method]&.to_sym
|
|
39
|
+
},
|
|
40
|
+
attributes: datum[:id] ? { id: datum[:id] } : {},
|
|
41
|
+
relationships: {}
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def meta_params
|
|
46
|
+
data[:meta] || {}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def process_relationships(relationship_hash)
|
|
50
|
+
{}.tap do |hash|
|
|
51
|
+
relationship_hash.each_pair do |name, relationship_payload|
|
|
52
|
+
name = name.to_sym
|
|
53
|
+
data_payload = relationship_payload[:data]
|
|
54
|
+
hash[name] = data_payload.nil? ? process_nil_relationship(name) : process_relationship(relationship_payload[:data])
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# change empty relationship as `disassociate` hash so they will be removed
|
|
60
|
+
def process_nil_relationship(name)
|
|
61
|
+
attributes = {}
|
|
62
|
+
method_name = :disassociate
|
|
63
|
+
|
|
64
|
+
{
|
|
65
|
+
meta: {
|
|
66
|
+
jsonapi_type: name.to_sym,
|
|
67
|
+
method: method_name
|
|
68
|
+
},
|
|
69
|
+
attributes: attributes,
|
|
70
|
+
relationships: {}
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def meta(action: nil)
|
|
75
|
+
results = super
|
|
76
|
+
return results if action.present? || @env.nil?
|
|
77
|
+
|
|
78
|
+
action = case @env['REQUEST_METHOD']
|
|
79
|
+
when 'POST' then :create
|
|
80
|
+
when 'PUT', 'PATCH' then :update
|
|
81
|
+
when 'DELETE' then :destroy
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
results[:method] = action
|
|
85
|
+
results
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def path_map
|
|
89
|
+
map = @params.select { |key, _| key =~ /_id$/ }.permit!.to_h
|
|
90
|
+
map = filter_keys(map) { |key| key.gsub(/_id$/, '').to_sym }
|
|
91
|
+
map = filter_keys(map) { |key| @parent_map[key] || key }
|
|
92
|
+
map = filter_keys_presence(map) if @model < ActiveGraph::Node
|
|
93
|
+
map
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def filter_keys_presence(map)
|
|
97
|
+
filter_keys(map) { |key| presence(key) || presence(key.to_s.pluralize.to_sym) }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def filter_keys(map)
|
|
101
|
+
map.map { |key, v| [yield(key), v] }.select(&:first).to_h
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def presence(key)
|
|
105
|
+
key if @model.associations.include?(key)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def detect_conflict(key, path_value, body_value)
|
|
109
|
+
raise Conflict.new(key, path_value, body_value) if path_value && body_value && body_value != path_value
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def parsable_content?
|
|
115
|
+
true
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def derive_resource_type(rel_name)
|
|
119
|
+
if @model.include?(ActiveGraph::Node)
|
|
120
|
+
@model.associations[rel_name].target_class.model_name.plural.to_s
|
|
121
|
+
else
|
|
122
|
+
# ApplicationRelationship resource doesn't have #associations or any other method to list all associations
|
|
123
|
+
# "from_class" and "to_class" methods can contain value "any". Which makes it unreliable to use here
|
|
124
|
+
# Using "rel_name.to_s.pluralize" as it works in most cases.
|
|
125
|
+
# User can define a method on controller "" which will override this behaviour
|
|
126
|
+
derive_resource_type_from_controller(rel_name) || rel_name.to_s.pluralize
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def derive_resource_type_from_controller(rel_name)
|
|
131
|
+
controller_obj.derive_parent_resource_type(rel_name) if controller_obj.respond_to?(:derive_parent_resource_type)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def controller_obj
|
|
135
|
+
@controller_obj ||= Graphiti.context[:object]
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
module Graphiti::ActiveGraph::Extensions
|
|
2
|
-
require 'ostruct' if RUBY_PLATFORM != 'java'
|
|
3
|
-
|
|
4
|
-
module Context
|
|
5
|
-
extend ActiveSupport::Concern
|
|
6
|
-
|
|
7
|
-
class_methods do
|
|
8
|
-
def context
|
|
9
|
-
Thread.current.thread_variable_get(:context) || {}.tap(&method(:context=))
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def context=(val)
|
|
13
|
-
Thread.current.thread_variable_set(:context, val)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
1
|
+
module Graphiti::ActiveGraph::Extensions
|
|
2
|
+
require 'ostruct' if RUBY_PLATFORM != 'java'
|
|
3
|
+
|
|
4
|
+
module Context
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
class_methods do
|
|
8
|
+
def context
|
|
9
|
+
Thread.current.thread_variable_get(:context) || {}.tap(&method(:context=))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def context=(val)
|
|
13
|
+
Thread.current.thread_variable_set(:context, val)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,52 +1,101 @@
|
|
|
1
|
-
module Graphiti::ActiveGraph::Extensions::Grouping
|
|
2
|
-
class Params
|
|
3
|
-
attr_reader :params, :grouping_criteria_list, :resource_class
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
intermediate_model
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
end
|
|
1
|
+
module Graphiti::ActiveGraph::Extensions::Grouping
|
|
2
|
+
class Params
|
|
3
|
+
attr_reader :params, :grouping_criteria_list, :resource_class
|
|
4
|
+
|
|
5
|
+
def initialize(params, resource_class)
|
|
6
|
+
@params = params
|
|
7
|
+
group_by_string = params.fetch(:group_by, nil)
|
|
8
|
+
@grouping_criteria_list = split_grouping_criteria(group_by_string)
|
|
9
|
+
@resource_class = resource_class
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def single_grouping_criteria?
|
|
13
|
+
grouping_criteria_list.size < 2
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def grouping_criteria_on_attribute?
|
|
17
|
+
grouping_criteria_list.any? { |criteria| ends_with_attribute?(resource_class.model, criteria) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def empty?
|
|
21
|
+
grouping_criteria_list.empty?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def ends_with_attribute?(model, criteria)
|
|
25
|
+
return false if criteria.blank?
|
|
26
|
+
|
|
27
|
+
last_segment_attribute?(model, criteria.split('.'))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def last_segment_attribute?(model, segments)
|
|
33
|
+
last_segment = segments.last
|
|
34
|
+
intermediate_model = traverse_to_last_associated_model(model, segments[0...-1])
|
|
35
|
+
|
|
36
|
+
intermediate_model && attribute?(intermediate_model, last_segment)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def traverse_to_last_associated_model(model, intermediate_segments)
|
|
40
|
+
intermediate_segments.each do |segment|
|
|
41
|
+
return false unless (model = associated_model(model, segment))
|
|
42
|
+
end
|
|
43
|
+
model
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def attribute?(model, segment)
|
|
47
|
+
model.attribute_names.include?(segment)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def associated_model(model, segment)
|
|
51
|
+
model.associations[segment.to_sym]&.target_class
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def split_grouping_criteria(group_by_string)
|
|
55
|
+
return [] if group_by_string.nil? || group_by_string.empty?
|
|
56
|
+
|
|
57
|
+
result = []
|
|
58
|
+
current = ''
|
|
59
|
+
depth = 0
|
|
60
|
+
|
|
61
|
+
group_by_string.each_char do |char|
|
|
62
|
+
depth, current = process_char(char, depth, current, result)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
add_criterion(result, current)
|
|
66
|
+
handle_mismatched_parentheses(result, depth)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def process_char(char, depth, current, result)
|
|
70
|
+
case char
|
|
71
|
+
when '(' then [depth + 1, current + char]
|
|
72
|
+
when ')' then [depth - 1, current + char]
|
|
73
|
+
when ',' then process_comma(depth, current, result)
|
|
74
|
+
else [depth, current + char]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def process_comma(depth, current, result)
|
|
79
|
+
if depth <= 0
|
|
80
|
+
add_criterion(result, current)
|
|
81
|
+
[depth, '']
|
|
82
|
+
else
|
|
83
|
+
[depth, current + ',']
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def add_criterion(result, current)
|
|
88
|
+
stripped = current.strip
|
|
89
|
+
result << stripped unless stripped.empty?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def handle_mismatched_parentheses(result, final_depth)
|
|
93
|
+
return result if final_depth <= 0 || result.empty?
|
|
94
|
+
|
|
95
|
+
# If we ended with unclosed parentheses, re-split the last segment
|
|
96
|
+
last_segment = result.pop
|
|
97
|
+
result.concat(last_segment.split(',').map(&:strip).reject(&:empty?))
|
|
98
|
+
result
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Graphiti::ActiveGraph::Extensions::QueryDsl
|
|
2
|
+
module Performer
|
|
3
|
+
attr_accessor :with_vars, :skip_arrow_cypher_rels
|
|
4
|
+
|
|
5
|
+
def apply_query_dsl
|
|
6
|
+
query_param = resource.context&.params&.[](:query)
|
|
7
|
+
query_param.present? ? apply_query_param(query_param) : scope
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def apply_query_param(query_param)
|
|
11
|
+
@scope = query_generator.new(query_param, **query_generator_config).tap do |qg|
|
|
12
|
+
qg.generate_functions_optional_match
|
|
13
|
+
qg.generate_with_clause_partition_query
|
|
14
|
+
qg.generate_match_query
|
|
15
|
+
qg.generate_with_clause_query
|
|
16
|
+
end.query
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def query_generator
|
|
22
|
+
Graphiti::ActiveGraph::Extensions::QueryDsl::QueryGenerator
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_generator_config
|
|
26
|
+
{
|
|
27
|
+
query: scope,
|
|
28
|
+
with_vars_to_carry:,
|
|
29
|
+
skip_arrow_cypher_rels: skip_arrow_cypher_rels || [],
|
|
30
|
+
resource: resource.class
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def with_vars_to_carry
|
|
35
|
+
(query ? with_vars_for_sort : []).push(*with_vars).push(*Graphiti.context[:with_vars]).compact
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Graphiti::ActiveGraph::Extensions::QueryDsl
|
|
2
|
+
class QueryGenerator
|
|
3
|
+
def initialize(query_param, query:, **config)
|
|
4
|
+
@query_param = query_param
|
|
5
|
+
@query = query
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def generate_functions_optional_match
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def generate_with_clause_partition_query
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def generate_match_query
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def generate_with_clause_query
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
module Graphiti::ActiveGraph::Extensions
|
|
2
|
-
class QueryParams
|
|
3
|
-
attr_reader :params, :grouping_extra_params, :resource_class
|
|
4
|
-
|
|
5
|
-
def initialize(params, resource_class, grouping_extra_params: {})
|
|
6
|
-
@params = params
|
|
7
|
-
@resource_class = resource_class
|
|
8
|
-
@grouping_extra_params = grouping_extra_params
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def group_by
|
|
12
|
-
Grouping::Params.new(params, resource_class)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def group_by_params
|
|
16
|
-
group_by_params_hash unless group_by.empty?
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def group_by_params_hash
|
|
20
|
-
{ group_by: group_by.grouping_criteria_list }.merge(grouping_extra_params)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def extra_field?(type, name)
|
|
24
|
-
params.dig(:extra_fields, type)&.include?(name.to_s)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
1
|
+
module Graphiti::ActiveGraph::Extensions
|
|
2
|
+
class QueryParams
|
|
3
|
+
attr_reader :params, :grouping_extra_params, :resource_class
|
|
4
|
+
|
|
5
|
+
def initialize(params, resource_class, grouping_extra_params: {})
|
|
6
|
+
@params = params
|
|
7
|
+
@resource_class = resource_class
|
|
8
|
+
@grouping_extra_params = grouping_extra_params
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def group_by
|
|
12
|
+
Grouping::Params.new(params, resource_class)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def group_by_params
|
|
16
|
+
group_by_params_hash unless group_by.empty?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def group_by_params_hash
|
|
20
|
+
{ group_by: group_by.grouping_criteria_list }.merge(grouping_extra_params)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def extra_field?(type, name)
|
|
24
|
+
params.dig(:extra_fields, type)&.include?(name.to_s)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
module Graphiti::ActiveGraph::Extensions::Resources
|
|
2
|
-
module Authorizationable
|
|
3
|
-
extend ActiveSupport::Concern
|
|
4
|
-
|
|
5
|
-
included do
|
|
6
|
-
class << self
|
|
7
|
-
attr_reader :authorize_attributes
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class_methods do
|
|
12
|
-
def attribute_authorization
|
|
13
|
-
@authorize_attributes = true
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def authorize_attributes?
|
|
17
|
-
@authorize_attributes
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def readable_attributes
|
|
21
|
-
attributes.select { |_attr_name, options_map| options_map[:readable] }
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def readable_sideloads
|
|
25
|
-
sideloads.select { |_sideloads_name, sideload_obj| sideload_obj.readable? }
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
1
|
+
module Graphiti::ActiveGraph::Extensions::Resources
|
|
2
|
+
module Authorizationable
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
class << self
|
|
7
|
+
attr_reader :authorize_attributes
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class_methods do
|
|
12
|
+
def attribute_authorization
|
|
13
|
+
@authorize_attributes = true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def authorize_attributes?
|
|
17
|
+
@authorize_attributes
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def readable_attributes
|
|
21
|
+
attributes.select { |_attr_name, options_map| options_map[:readable] }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def readable_sideloads
|
|
25
|
+
sideloads.select { |_sideloads_name, sideload_obj| sideload_obj.readable? }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|