graphiti_gql 0.2.19 → 0.2.22

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: 8ff3654600729760d759d234decc94aeb9fd1927b27017bf14de01c70080ec34
4
- data.tar.gz: 9e9cc547ace2c05ffbd9952cbe8db82ae9ef499ecc5123deaf72f2087cd6147b
3
+ metadata.gz: 1a79d794e346a1f884170026503f4ca36a5c82529a47dd977b34335457d4a630
4
+ data.tar.gz: 0ee188c2f278895a47b27c8dbe57b1117dfe352350a99bec8a908702cc782411
5
5
  SHA512:
6
- metadata.gz: 496ee06e3e0ba183c867367a759ce0114764c183f0af8df346d18bf8c28bb1c034ba9aa7dcf43d8e04bb11106b05143fdc2d6fd0ca220089489e276d59079a84
7
- data.tar.gz: a2b5b3a60d06253dcb0aad59fe7f5358c700e360ecd24c421fed659ac2dccce45f3492797d42c74c72e743c7488a7f02417daf8f0352372f87b9faa49af21f96
6
+ metadata.gz: d4eb9c8bb29c513cc9b8eed6e7dafffbefa1de88ab9e1dbc32d1f921b0664ee066c671d36c05eeb15614accded9ba56d4247010ea9c83bf55e0f76ae4d036b31
7
+ data.tar.gz: 014ee03255a4c2b26bbe178d6c60f4f071955a288dac725aa75ae84dcd6624bde251442ea3f7e7811bae4ec9b7f463f024cdcc5c3c4f6f90ec8575e7eb071999
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_gql (0.2.18)
4
+ graphiti_gql (0.2.21)
5
+ activemodel (> 6.0, < 8.0)
5
6
  graphiti (~> 1.3.9)
6
7
  graphql (~> 2.0)
7
8
  graphql-batch (~> 0.5)
@@ -82,7 +83,6 @@ PLATFORMS
82
83
  arm64-darwin-21
83
84
 
84
85
  DEPENDENCIES
85
- activemodel (~> 7.0)
86
86
  bundler (~> 2.3)
87
87
  graphiti_gql!
88
88
  pry
data/graphiti_gql.gemspec CHANGED
@@ -38,9 +38,9 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency "graphql", "~> 2.0"
39
39
  spec.add_dependency "graphql-batch", "~> 0.5"
40
40
  spec.add_dependency "graphiti", "~> 1.3.9"
41
+ spec.add_dependency "activemodel", ["> 6.0", "< 8.0"]
41
42
 
42
43
  spec.add_development_dependency "bundler", "~> 2.3"
43
44
  spec.add_development_dependency "rake", "~> 10.0"
44
45
  spec.add_development_dependency "rspec", "~> 3.0"
45
- spec.add_development_dependency "activemodel", "~> 7.0"
46
46
  end
@@ -74,6 +74,7 @@ module GraphitiGql
74
74
 
75
75
  def node(id = nil)
76
76
  if @resource.singular
77
+ data # fire query
77
78
  Node.new(underscore(data[data.keys.first]), @resource)
78
79
  else
79
80
  nodes.find { |n| n.id == id.to_s }
@@ -16,7 +16,10 @@ module GraphitiGql
16
16
  module ResourceExtras
17
17
  extend ActiveSupport::Concern
18
18
 
19
- included do
19
+ prepended do
20
+ extend ActiveModel::Callbacks
21
+ define_model_callbacks :query
22
+
20
23
  class << self
21
24
  attr_accessor :graphql_name, :singular
22
25
  end
@@ -57,7 +60,14 @@ module GraphitiGql
57
60
  @selections
58
61
  end
59
62
 
63
+ def around_scoping(original_scope, query_hash)
64
+ run_callbacks :query do
65
+ super { |scope| yield scope }
66
+ end
67
+ end
68
+
60
69
  class_methods do
70
+
61
71
  def attribute(*args)
62
72
  super(*args).tap do
63
73
  opts = args.extract_options!
@@ -85,7 +95,7 @@ module GraphitiGql
85
95
  end
86
96
  end
87
97
  end
88
- Graphiti::Resource.send(:include, ResourceExtras)
98
+ Graphiti::Resource.send(:prepend, ResourceExtras)
89
99
 
90
100
  module FilterExtras
91
101
  def filter_param
@@ -269,7 +279,7 @@ module GraphitiGql
269
279
  module ActiveRecordAdapterExtras
270
280
  extend ActiveSupport::Concern
271
281
 
272
- included do
282
+ prepended do
273
283
  alias_method :filter_precise_datetime_lt, :filter_lt
274
284
  alias_method :filter_precise_datetime_lte, :filter_lte
275
285
  alias_method :filter_precise_datetime_gt, :filter_gt
@@ -277,16 +287,59 @@ module GraphitiGql
277
287
  alias_method :filter_precise_datetime_eq, :filter_eq
278
288
  alias_method :filter_precise_datetime_not_eq, :filter_not_eq
279
289
  end
290
+
291
+ # TODO: integration specs mysql vs postgres for case sensitivity
292
+ def mysql?(scope)
293
+ mysql = ActiveRecord::ConnectionAdapters::Mysql2Adapter
294
+ scope.model.connection.is_a?(mysql)
295
+ end
296
+
297
+ def filter_string_eq(scope, attribute, value, is_not: false)
298
+ if mysql?(scope)
299
+ clause = { attribute => value }
300
+ is_not ? scope.where.not(clause) : scope.where(clause)
301
+ else
302
+ # og behavior
303
+ column = column_for(scope, attribute)
304
+ clause = column.lower.eq_any(value.map(&:downcase))
305
+ end
306
+ end
307
+
308
+ def filter_string_eql(scope, attribute, value, is_not: false)
309
+ if mysql?(scope)
310
+ value = "BINARY #{value}"
311
+ end
312
+ # og behavior
313
+ clause = {attribute => value}
314
+ is_not ? scope.where.not(clause) : scope.where(clause)
315
+ end
316
+
317
+ def sanitized_like_for(scope, attribute, value, &block)
318
+ escape_char = "\\"
319
+ column = column_for(scope, attribute)
320
+ map = value.map { |v|
321
+ v = v.downcase unless mysql?(scope)
322
+ v = Sanitizer.sanitize_like(v, escape_char)
323
+ block.call v
324
+ }
325
+ arel = column
326
+ arel = arel.lower unless mysql?(scope)
327
+ arel.matches_any(map, escape_char, true)
328
+ end
280
329
  end
281
330
  if defined?(Graphiti::Adapters::ActiveRecord)
282
- Graphiti::Adapters::ActiveRecord.send(:include, ActiveRecordAdapterExtras)
331
+ Graphiti::Adapters::ActiveRecord.send(:prepend, ActiveRecordAdapterExtras)
283
332
  end
284
333
 
285
334
  Graphiti::Adapters::Abstract.class_eval do
286
335
  class << self
287
336
  alias :old_default_operators :default_operators
288
337
  def default_operators
289
- old_default_operators.merge(precise_datetime: numerical_operators)
338
+ old_default_operators.merge({
339
+ precise_datetime: numerical_operators,
340
+ string_enum: [:eq, :not_eq],
341
+ integer_enum: [:eq, :not_eq],
342
+ })
290
343
  end
291
344
  end
292
345
  end
@@ -1,3 +1,3 @@
1
1
  module GraphitiGql
2
- VERSION = "0.2.19"
2
+ VERSION = "0.2.22"
3
3
  end
data/lib/graphiti_gql.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "active_support/core_ext/object/json"
2
2
  require "graphql"
3
3
  require 'graphql/batch'
4
+ require 'active_model'
4
5
  require "graphiti_gql/graphiti_hax"
5
6
  require "graphiti_gql/version"
6
7
  require "graphiti_gql/errors"
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.19
4
+ version: 0.2.22
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-01 00:00:00.000000000 Z
11
+ date: 2022-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -52,6 +52,26 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.3.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '8.0'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">"
70
+ - !ruby/object:Gem::Version
71
+ version: '6.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '8.0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: bundler
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +114,6 @@ dependencies:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
116
  version: '3.0'
97
- - !ruby/object:Gem::Dependency
98
- name: activemodel
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '7.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '7.0'
111
117
  description:
112
118
  email:
113
119
  - richmolj@gmail.com
@@ -124,7 +130,6 @@ files:
124
130
  - LICENSE.txt
125
131
  - README.md
126
132
  - Rakefile
127
- - app/controllers/graphiti_gql/execution_controller.rb
128
133
  - bin/bundle
129
134
  - bin/byebug
130
135
  - bin/coderay
@@ -136,7 +141,6 @@ files:
136
141
  - bin/rake
137
142
  - bin/rspec
138
143
  - bin/setup
139
- - config/routes.rb
140
144
  - graphiti_gql.gemspec
141
145
  - lib/graphiti_gql.rb
142
146
  - 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
data/config/routes.rb DELETED
@@ -1,6 +0,0 @@
1
- GraphitiGql::Engine.routes.draw do
2
- # Default json so our error handler takes effect
3
- scope defaults: {format: :json} do
4
- post "/" => "execution#execute"
5
- end
6
- end