graphql-active_record 1.0.0 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45115b2145e11a13330473d364a94790d919e3ea
4
- data.tar.gz: e52d540737421aa06ac82a6b7b87ae7fa8519268
3
+ metadata.gz: be83c7bf1ca2f204d1df9c13f29034e5992181ad
4
+ data.tar.gz: 664477e103aab5c42c738f7af3cde361a66e051c
5
5
  SHA512:
6
- metadata.gz: 6451c770f4f7d385259fae307deb0e294b69ba8a8f931bf1a735f04c34f4f63498bdc05ef54c7aa1756b0d80d3d4fdf2c6bea69ef7df7fae8b6282d6dda703c8
7
- data.tar.gz: 5cdb683ecb4891d1d0abc625cab9514d0b15fe18bb82d14fb42512e2d26fdcd653c8ccc160e8cf169ba01647b72fd9448b9c2617df662b81ae804410a19afcdb
6
+ metadata.gz: 839bd98b001fe11a45e60e91579f0293f0a43821100c120829df6c8fc2fdca51c86910e11cb62d67c057897e2402ff897e5cfeb03455aa5b6c3f2d787b8ebbb8
7
+ data.tar.gz: b7cf189372b10f94a6a426b45ecee90024e3a44e574eb4d31f19d5c2bc52fcb342235dd2634fb5084e23b0ad0e2e450db57d70277165036a21e6f99d41ae25dc
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@
2
2
  language: ruby
3
3
  cache: bundler
4
4
  rvm:
5
- - "2.2.4"
5
+ - "2.3.1"
6
6
  script: 'bundle exec rake'
7
7
 
8
8
  gemfile:
data/CHANGELOG.md CHANGED
@@ -1,2 +1,10 @@
1
+ # version 2.0.0
2
+ Make a lot of changes, in order to support more recent versions of graphql-ruby.
3
+
4
+ Breaking Change:
5
+ - `#new` was removed. Use `#generate` instead
6
+ - `type` argument was renamed to `resolve_type`
7
+
8
+
1
9
  # version 1.0.0
2
10
  Move uuid to an argument instead [#1](https://github.com/brettjurgens/graphql-active-record/pull/1)
data/README.md CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
  Use like:
26
26
 
27
27
  ```ruby
28
- GraphQL::ActiveRecordExtensions::Field.new(type: Type, model: Model)
28
+ GraphQL::ActiveRecordExtensions::Field.generate(resolve_type: Type, model: Model)
29
29
  ```
30
30
 
31
31
  ## Development
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "graphql", "~> 0.8"
21
+ spec.add_runtime_dependency "graphql", "~> 0.18.11"
22
22
  spec.add_runtime_dependency "activerecord"
23
23
 
24
24
  spec.add_development_dependency "appraisal"
@@ -4,22 +4,20 @@
4
4
  # somewhat more efficient (hopefully)
5
5
  module GraphQL
6
6
  module ActiveRecordExtensions
7
- class Field < ::GraphQL::Field
8
- def initialize(model:, type:)
9
- @model = model
10
-
11
- self.type = type
12
- self.description = "Find a #{model.name} by ID"
13
- self.arguments = {
14
- 'id' => GraphQL::Argument.define do
15
- type !GraphQL::ID_TYPE
16
- description "Id for record"
17
- end,
18
- 'use_uuid' => GraphQL::Argument.define do
19
- type GraphQL::BOOLEAN_TYPE
20
- description "Whether or not to use UUID"
21
- end,
22
- }
7
+ class Field
8
+ def self.generate(model:, resolve_type:)
9
+ GraphQL::Field.define do
10
+ name(model.name.underscore)
11
+ type(resolve_type)
12
+ description("Find a #{model.name} by ID/UUID")
13
+
14
+ argument :id, !GraphQL::ID_TYPE
15
+ argument :use_uuid, GraphQL::BOOLEAN_TYPE
16
+
17
+ resolve -> (object, arguments, context) do
18
+ GraphQL::ActiveRecordExtensions::Field.resolve_it(model, object, arguments, context)
19
+ end
20
+ end
23
21
  end
24
22
 
25
23
  ##
@@ -32,10 +30,10 @@ module GraphQL
32
30
  # @param ctx [GraphQL::Context] the context of the GraphQL query
33
31
  #
34
32
  # @return eager-loaded ActiveRecord model
35
- def resolve(object, arguments, ctx)
36
- includes = map_includes(@model, ctx.ast_node.selections, ctx)
33
+ def self.resolve_it(model, object, arguments, ctx)
34
+ includes = map_includes(model, ctx.ast_node.selections, ctx)
37
35
 
38
- model_with_includes = include_in_model(@model, includes)
36
+ model_with_includes = include_in_model(model, includes)
39
37
 
40
38
  if arguments['use_uuid']
41
39
  model_with_includes.find_by_uuid(arguments['id'])
@@ -44,12 +42,12 @@ module GraphQL
44
42
  end
45
43
 
46
44
  rescue ActiveRecord::ConfigurationError => e
47
- @model.find(arguments['id'])
45
+ model.find(arguments['id'])
48
46
  end
49
47
 
50
48
  private
51
49
 
52
- def include_in_model(model, includes)
50
+ def self.include_in_model(model, includes)
53
51
  includes.present? ? model.includes(*includes) : model
54
52
  end
55
53
 
@@ -63,7 +61,7 @@ module GraphQL
63
61
  # @param ctx [GraphQL::Context] the context of the GraphQL query. Used to map fragments to models
64
62
  #
65
63
  # @return Array of tables to include in the query
66
- def map_includes(model, selections, ctx)
64
+ def self.map_includes(model, selections, ctx)
67
65
  selections.map do |selection|
68
66
 
69
67
  table_name, node = handle_fragments(selection, ctx)
@@ -123,7 +121,7 @@ module GraphQL
123
121
  # @param ctx [GraphQL::Context] GQL Context used to map fragment to node
124
122
  #
125
123
  # @return [String, GraphQL::Language::Nodes::*] tuple of node name and node
126
- def handle_fragments(node, ctx)
124
+ def self.handle_fragments(node, ctx)
127
125
  if node.class == GraphQL::Language::Nodes::FragmentSpread
128
126
  fragment = ctx.query.fragments[node.name]
129
127
  [fragment.type.underscore, fragment]
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module ActiveRecordExtensions
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Jurgens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-04 00:00:00.000000000 Z
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: 0.18.11
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: 0.18.11
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -231,3 +231,4 @@ signing_key:
231
231
  specification_version: 4
232
232
  summary: Active Record Helpers for graphql-ruby
233
233
  test_files: []
234
+ has_rdoc: