graphql-activerecord 0.11.0 → 0.12.0

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
  SHA1:
3
- metadata.gz: 0898e348a67f2ffea03d24b07bad53f4ee4e303c
4
- data.tar.gz: fe1f6ef15222a43dabb77ee545a8fbb22bf5509c
3
+ metadata.gz: f253c809829eb5ccf3b269799ddcda31457ed9bd
4
+ data.tar.gz: e5ab0b719842b6391145d41a7eaf4e08e1de10a8
5
5
  SHA512:
6
- metadata.gz: d224b60c12152281cba045789a6c0122740b65368ea14e9327ca794a87db2ba82a1415b8ab63cff0565b04be8cf803004c7ad5c7f3b55d0468d31bf24e68eb82
7
- data.tar.gz: 3568541b0befd15885528e980a63a18295764ccc35f47207400d0d48439a3ee42d1121efa143303f3de2fca7941def87c414ca420bb2208c082ef210a5aaf79f
6
+ metadata.gz: 5d08fad7ea034c1d43ca80dad54c2dbec6fec4eef629b9cc6a8f62e307f96c5ea7d9c2442ea6d1118833e64aad1aa3ee9309888c40f6833c1c45f17854b0e120
7
+ data.tar.gz: d578f4ccb32476553518484b18748cdbb956e242ab3a702d93c43d04e491e8ed0a15c76afb718497e5612f5a1080c54cd5ae10254e14ef48c73b23651b9f9fd2
data/.rubocop.yml CHANGED
@@ -123,3 +123,6 @@ Style/BracesAroundHashParameters:
123
123
 
124
124
  Style/IndentationWidth:
125
125
  Enabled: false
126
+
127
+ Style/BlockDelimiters:
128
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ # 0.12.0
4
+ This version is focussed on compatibility with the GraphQL 1.5.10. Changes are relatively minor, and mostly are in response to the udpated way that connections are handled in the graphql gem now.
5
+
6
+ Breaking Changes:
7
+ The middleware that the gem uses for preloading associations has been replaced with instrumentation. So instead of this:
8
+ ```ruby
9
+ Schema.define do
10
+ # other stuff
11
+ middleware GraphQL::Models::Middleware.new
12
+ end
13
+ ```
14
+ You should do this:
15
+ ```ruby
16
+ Schema.define do
17
+ # other stuff
18
+ instrument :field, GraphQL::Models::Instrumentation.new
19
+ end
20
+ ```
21
+ If you were using the `skip_nil_models` option to force your field resolvers to be invoked even when the model ends up not existing, it is available on instrumentation.
22
+
3
23
  # 0.11.0
4
24
  Breaking Bug Fix: Turns out that 0.10.0 was _supposed_ to introduce (non)nullability on attributes, but it didn’t quite work. That’s
5
25
  fixed in 0.11.0 (and, I _really_ need to write some tests for this gem).
data/README.md CHANGED
@@ -142,8 +142,8 @@ GraphQL::Schema.define do
142
142
  lazy_resolve(Promise, :sync)
143
143
  instrument(:query, GraphQL::Batch::Setup)
144
144
 
145
- # This middleware should be somewhere near the top of your middleware chain
146
- middleware GraphQL::Models::Middleware.new
145
+ # Set up the graphql-activerecord gem
146
+ instrument(:field, GraphQL::Models::Instrumentation.new)
147
147
  end
148
148
  ```
149
149
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency "activesupport", ">= 4.2", '< 5'
24
24
  spec.add_runtime_dependency "activerecord", ">= 4.2", '< 5'
25
- spec.add_runtime_dependency "graphql", ">= 1.4", '< 2'
25
+ spec.add_runtime_dependency "graphql", ">= 1.5.10", '< 2'
26
26
  spec.add_runtime_dependency "graphql-batch", ">= 0.2.4"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.11"
@@ -7,7 +7,7 @@ require 'graphql/relay'
7
7
 
8
8
  require 'graphql/models/monkey_patches/graphql_query_context'
9
9
  require 'graphql/models/active_record_extension'
10
- require 'graphql/models/middleware'
10
+ require 'graphql/models/instrumentation'
11
11
 
12
12
  # Helpers
13
13
  require 'graphql/models/helpers'
@@ -215,7 +215,7 @@ module GraphQL
215
215
  connection_type = connection_type.to_non_null_type
216
216
  end
217
217
 
218
- camel_name = options[:name]
218
+ camel_name = options[:name].to_s
219
219
 
220
220
  DefinitionHelpers.register_field_metadata(graph_type, camel_name, {
221
221
  macro: :has_many_connection,
@@ -227,12 +227,20 @@ module GraphQL
227
227
  object_to_base_model: object_to_model,
228
228
  })
229
229
 
230
- GraphQL::Define::AssignConnection.call(graph_type, camel_name, connection_type) do
230
+ connection_field = graph_type.fields[camel_name] = GraphQL::Field.define do
231
+ name(camel_name)
232
+ type(connection_type)
233
+ description options[:description] if options.include?(:description)
234
+ deprecation_reason options[:deprecation_reason] if options.include?(:deprecation_reason)
235
+
231
236
  resolve -> (model, _args, _context) do
232
237
  return nil unless model
233
238
  model.public_send(association)
234
239
  end
235
240
  end
241
+
242
+ connection_field.connection = true
243
+ connection_field
236
244
  end
237
245
  end
238
246
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ class GraphQL::Models::Instrumentation
3
+ # @param skip_nil_models If true, field resolvers (in proxy_to or backed_by_model blocks) will not be invoked if the model is nil.
4
+ def initialize(skip_nil_models = true)
5
+ @skip_nil_models = skip_nil_models
6
+ end
7
+
8
+ def instrument(type, field)
9
+ field_info = GraphQL::Models.field_info(type, field.name)
10
+ return field unless field_info
11
+
12
+ old_resolver = field.resolve_proc
13
+
14
+ new_resolver = -> (object, args, ctx) {
15
+ base_model = field_info.object_to_base_model.call(object)
16
+ GraphQL::Models.load_association(base_model, field_info.path, ctx).then do |model|
17
+ next nil if model.nil? && @skip_nil_models
18
+ old_resolver.call(model, args, ctx)
19
+ end
20
+ }
21
+
22
+ field.redefine do
23
+ resolve(new_resolver)
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module GraphQL
3
3
  module Models
4
- VERSION = "0.11.0"
4
+ VERSION = "0.12.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Foster
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-07 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -56,7 +56,7 @@ dependencies:
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '1.4'
59
+ version: 1.5.10
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '2'
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: '1.4'
69
+ version: 1.5.10
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '2'
@@ -203,7 +203,7 @@ files:
203
203
  - lib/graphql/models/definition_helpers/attributes.rb
204
204
  - lib/graphql/models/hash_combiner.rb
205
205
  - lib/graphql/models/helpers.rb
206
- - lib/graphql/models/middleware.rb
206
+ - lib/graphql/models/instrumentation.rb
207
207
  - lib/graphql/models/monkey_patches/graphql_query_context.rb
208
208
  - lib/graphql/models/mutation_field_map.rb
209
209
  - lib/graphql/models/mutation_helpers/apply_changes.rb
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
- class GraphQL::Models::Middleware
3
- attr_accessor :skip_nil_models
4
-
5
- def initialize(skip_nil_models = true)
6
- @skip_nil_models = skip_nil_models
7
- end
8
-
9
- def call(graphql_type, object, field_definition, args, context)
10
- # If this field defines a path, load the associations in the path
11
- field_info = GraphQL::Models.field_info(graphql_type, field_definition.name)
12
- return yield unless field_info
13
-
14
- # Convert the core object into the model
15
- base_model = field_info.object_to_base_model.call(object)
16
-
17
- GraphQL::Models.load_association(base_model, field_info.path, context).then do |model|
18
- next nil if model.nil? && @skip_nil_models
19
-
20
- next_args = [graphql_type, model, field_definition, args, context]
21
- yield(next_args)
22
- end
23
- end
24
- end