graphiti_gql 0.2.18 → 0.2.21
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/Gemfile.lock +1 -1
- data/lib/graphiti_gql/active_resource.rb +1 -0
- data/lib/graphiti_gql/graphiti_hax.rb +46 -3
- data/lib/graphiti_gql/schema/fields/attribute.rb +29 -8
- data/lib/graphiti_gql/schema/fields/to_many.rb +1 -1
- data/lib/graphiti_gql/schema/resource_type.rb +1 -1
- data/lib/graphiti_gql/version.rb +1 -1
- metadata +2 -4
- data/app/controllers/graphiti_gql/execution_controller.rb +0 -18
- data/config/routes.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 933f1a2f88f12ad842f261023b05c8f5cc764ffbe61e7c6686ad88e2d013f8c8
|
|
4
|
+
data.tar.gz: 89f3c1c9fd1dcaa5160e1b0f9df9e81c0ff869a55d2842db365a1dfd14c942fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2de7c71483561731e957887da213322caf2c10b9d6836660b15ecd6572c743dffc1f34de139d15ff05dae13392b28186e35b01a2ee409cbe5c22f86c4a75066e
|
|
7
|
+
data.tar.gz: 973e35034e8c7a2b01eb5301f8db86df99a1631adfadf35e6e608f95fa31aec08d89da68df8833edc460af5525a8c3e240ff70d3576fc5180ef98614e87f58d3
|
data/Gemfile.lock
CHANGED
|
@@ -269,7 +269,7 @@ module GraphitiGql
|
|
|
269
269
|
module ActiveRecordAdapterExtras
|
|
270
270
|
extend ActiveSupport::Concern
|
|
271
271
|
|
|
272
|
-
|
|
272
|
+
prepended do
|
|
273
273
|
alias_method :filter_precise_datetime_lt, :filter_lt
|
|
274
274
|
alias_method :filter_precise_datetime_lte, :filter_lte
|
|
275
275
|
alias_method :filter_precise_datetime_gt, :filter_gt
|
|
@@ -277,16 +277,59 @@ module GraphitiGql
|
|
|
277
277
|
alias_method :filter_precise_datetime_eq, :filter_eq
|
|
278
278
|
alias_method :filter_precise_datetime_not_eq, :filter_not_eq
|
|
279
279
|
end
|
|
280
|
+
|
|
281
|
+
# TODO: integration specs mysql vs postgres for case sensitivity
|
|
282
|
+
def mysql?(scope)
|
|
283
|
+
mysql = ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
284
|
+
scope.model.connection.is_a?(mysql)
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def filter_string_eq(scope, attribute, value, is_not: false)
|
|
288
|
+
if mysql?(scope)
|
|
289
|
+
clause = { attribute => value }
|
|
290
|
+
is_not ? scope.where.not(clause) : scope.where(clause)
|
|
291
|
+
else
|
|
292
|
+
# og behavior
|
|
293
|
+
column = column_for(scope, attribute)
|
|
294
|
+
clause = column.lower.eq_any(value.map(&:downcase))
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def filter_string_eql(scope, attribute, value, is_not: false)
|
|
299
|
+
if mysql?(scope)
|
|
300
|
+
value = "BINARY #{value}"
|
|
301
|
+
end
|
|
302
|
+
# og behavior
|
|
303
|
+
clause = {attribute => value}
|
|
304
|
+
is_not ? scope.where.not(clause) : scope.where(clause)
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def sanitized_like_for(scope, attribute, value, &block)
|
|
308
|
+
escape_char = "\\"
|
|
309
|
+
column = column_for(scope, attribute)
|
|
310
|
+
map = value.map { |v|
|
|
311
|
+
v = v.downcase unless mysql?(scope)
|
|
312
|
+
v = Sanitizer.sanitize_like(v, escape_char)
|
|
313
|
+
block.call v
|
|
314
|
+
}
|
|
315
|
+
arel = column
|
|
316
|
+
arel = arel.lower unless mysql?(scope)
|
|
317
|
+
arel.matches_any(map, escape_char, true)
|
|
318
|
+
end
|
|
280
319
|
end
|
|
281
320
|
if defined?(Graphiti::Adapters::ActiveRecord)
|
|
282
|
-
Graphiti::Adapters::ActiveRecord.send(:
|
|
321
|
+
Graphiti::Adapters::ActiveRecord.send(:prepend, ActiveRecordAdapterExtras)
|
|
283
322
|
end
|
|
284
323
|
|
|
285
324
|
Graphiti::Adapters::Abstract.class_eval do
|
|
286
325
|
class << self
|
|
287
326
|
alias :old_default_operators :default_operators
|
|
288
327
|
def default_operators
|
|
289
|
-
old_default_operators.merge(
|
|
328
|
+
old_default_operators.merge({
|
|
329
|
+
precise_datetime: numerical_operators,
|
|
330
|
+
string_enum: [:eq, :not_eq],
|
|
331
|
+
integer_enum: [:eq, :not_eq],
|
|
332
|
+
})
|
|
290
333
|
end
|
|
291
334
|
end
|
|
292
335
|
end
|
|
@@ -3,7 +3,8 @@ module GraphitiGql
|
|
|
3
3
|
module Fields
|
|
4
4
|
class Attribute
|
|
5
5
|
# If sideload is present, we're applying m2m metadata to an edge
|
|
6
|
-
def initialize(name, config, sideload = nil)
|
|
6
|
+
def initialize(resource, name, config, sideload = nil)
|
|
7
|
+
@resource = resource
|
|
7
8
|
@config = config
|
|
8
9
|
@name = name
|
|
9
10
|
@alias = config[:alias]
|
|
@@ -57,14 +58,34 @@ module GraphitiGql
|
|
|
57
58
|
private
|
|
58
59
|
|
|
59
60
|
def field_type
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
field_type =
|
|
64
|
-
|
|
61
|
+
if [:integer_enum, :string_enum].any? { |t| @config[:type] == t }
|
|
62
|
+
return find_or_create_enum_type
|
|
63
|
+
else
|
|
64
|
+
field_type = Graphiti::Types[@config[:type]][:graphql_type]
|
|
65
|
+
if !field_type
|
|
66
|
+
canonical_graphiti_type = Graphiti::Types.name_for(@config[:type])
|
|
67
|
+
field_type = GQL_TYPE_MAP[canonical_graphiti_type.to_sym]
|
|
68
|
+
field_type = String if @name == :id
|
|
69
|
+
end
|
|
70
|
+
field_type = [field_type] if @config[:type].to_s.starts_with?("array_of")
|
|
71
|
+
field_type
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def find_or_create_enum_type
|
|
76
|
+
resource_type_name = Schema.registry.key_for(@resource, interface: false)
|
|
77
|
+
enum_type_name = "#{resource_type_name}_#{@name}"
|
|
78
|
+
if (registered = Schema.registry[enum_type_name])
|
|
79
|
+
registered[:type]
|
|
80
|
+
else
|
|
81
|
+
klass = Class.new(GraphQL::Schema::Enum)
|
|
82
|
+
klass.graphql_name(enum_type_name)
|
|
83
|
+
@config[:allow].each do |allowed|
|
|
84
|
+
klass.value(allowed)
|
|
85
|
+
end
|
|
86
|
+
Schema.registry[enum_type_name] = { type: klass }
|
|
87
|
+
klass
|
|
65
88
|
end
|
|
66
|
-
field_type = [field_type] if @config[:type].to_s.starts_with?("array_of")
|
|
67
|
-
field_type
|
|
68
89
|
end
|
|
69
90
|
end
|
|
70
91
|
end
|
|
@@ -64,7 +64,7 @@ module GraphitiGql
|
|
|
64
64
|
edge_resource = @sideload.class.edge_resource
|
|
65
65
|
edge_resource.attributes.each_pair do |name, config|
|
|
66
66
|
next if name == :id
|
|
67
|
-
Schema::Fields::Attribute.new(name, config, @sideload).apply(edge_type_class)
|
|
67
|
+
Schema::Fields::Attribute.new(edge_resource, name, config, @sideload).apply(edge_type_class)
|
|
68
68
|
end
|
|
69
69
|
registered_parent = Schema.registry.get(@sideload.parent_resource.class)
|
|
70
70
|
parent_name = registered_parent[:type].graphql_name
|
|
@@ -90,7 +90,7 @@ module GraphitiGql
|
|
|
90
90
|
def add_fields(type, resource)
|
|
91
91
|
resource.attributes.each_pair do |name, config|
|
|
92
92
|
if config[:readable]
|
|
93
|
-
Fields::Attribute.new(name, config).apply(type)
|
|
93
|
+
Fields::Attribute.new(@resource, name, config).apply(type)
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
end
|
data/lib/graphiti_gql/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: graphiti_gql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.21
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lee Richmond
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-08-
|
|
11
|
+
date: 2022-08-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: graphql
|
|
@@ -124,7 +124,6 @@ files:
|
|
|
124
124
|
- LICENSE.txt
|
|
125
125
|
- README.md
|
|
126
126
|
- Rakefile
|
|
127
|
-
- app/controllers/graphiti_gql/execution_controller.rb
|
|
128
127
|
- bin/bundle
|
|
129
128
|
- bin/byebug
|
|
130
129
|
- bin/coderay
|
|
@@ -136,7 +135,6 @@ files:
|
|
|
136
135
|
- bin/rake
|
|
137
136
|
- bin/rspec
|
|
138
137
|
- bin/setup
|
|
139
|
-
- config/routes.rb
|
|
140
138
|
- graphiti_gql.gemspec
|
|
141
139
|
- lib/graphiti_gql.rb
|
|
142
140
|
- lib/graphiti_gql/active_resource.rb
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module GraphitiGql
|
|
2
|
-
class ExecutionController < GraphitiGql.config.application_controller
|
|
3
|
-
def execute
|
|
4
|
-
params = request.params # avoid strong_parameters
|
|
5
|
-
variables = params[:variables] || {}
|
|
6
|
-
result = GraphitiGql.run params[:query],
|
|
7
|
-
params[:variables],
|
|
8
|
-
graphql_context
|
|
9
|
-
render json: result
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
def default_context
|
|
15
|
-
defined?(:current_user)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|