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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/graphql-active-record.gemspec +1 -1
- data/lib/graphql/active_record_extensions/field.rb +21 -23
- data/lib/graphql/active_record_extensions/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be83c7bf1ca2f204d1df9c13f29034e5992181ad
|
4
|
+
data.tar.gz: 664477e103aab5c42c738f7af3cde361a66e051c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 839bd98b001fe11a45e60e91579f0293f0a43821100c120829df6c8fc2fdca51c86910e11cb62d67c057897e2402ff897e5cfeb03455aa5b6c3f2d787b8ebbb8
|
7
|
+
data.tar.gz: b7cf189372b10f94a6a426b45ecee90024e3a44e574eb4d31f19d5c2bc52fcb342235dd2634fb5084e23b0ad0e2e450db57d70277165036a21e6f99d41ae25dc
|
data/.travis.yml
CHANGED
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
@@ -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.
|
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
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
36
|
-
includes = map_includes(
|
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(
|
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
|
-
|
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]
|
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:
|
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-
|
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:
|
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:
|
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:
|