graphql-rails-resolver 0.2.3 → 0.2.4
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/CHANGELOG.md +5 -0
- data/lib/graphql/rails/resolver.rb +41 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4113268e7739312f6ac4f42a9eb6ae4b9f70684a
|
4
|
+
data.tar.gz: e2c711048172d3fdbe2260b236d09118f44c69b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bce6833bfc2057460610600a79f538e76b52d0340abf018ff3ace056a0bcf3e2f72d5b167d10903ae76139b9be6e1c714f6364dbe34b710988408ad3dd20f44
|
7
|
+
data.tar.gz: adf079f574b375f4ea02aa83b86191fb73748910cd24d14fbbe39651a3ee8b0f8607be5a4f0d6ca0c5b9bd20b71f01293affcc6a8bd44d062b8ab38cb23df8ab
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# GraphQL::Rails::Resolver
|
2
2
|
## CHANGELOG
|
3
3
|
|
4
|
+
### Version 0.2.4
|
5
|
+
Adds ID resolution for non-primary ID field arguments
|
6
|
+
Adds `get_field_args` to get type declarations for arguments
|
7
|
+
Adds `get_arg_type`, `is_field_id_type?`, and `is_arg_id_type?`
|
8
|
+
|
4
9
|
### Version 0.2.2
|
5
10
|
Fixed arguments to :scope resolution
|
6
11
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GraphQL
|
2
2
|
module Rails
|
3
3
|
class Resolver
|
4
|
-
VERSION = '0.2.
|
4
|
+
VERSION = '0.2.4'
|
5
5
|
|
6
6
|
attr_accessor :resolvers
|
7
7
|
|
@@ -26,13 +26,13 @@ module GraphQL
|
|
26
26
|
@result = @callable.call(obj, args, ctx)
|
27
27
|
|
28
28
|
# If there's an ID type, offer ID resolution_strategy
|
29
|
-
if has_id_argument and args.key? @id_field
|
29
|
+
if has_id_argument? and args.key? @id_field
|
30
30
|
@result = resolve_id(args[@id_field])
|
31
31
|
end
|
32
32
|
|
33
|
-
@resolvers.each do |
|
34
|
-
if args.key?
|
35
|
-
value = args[
|
33
|
+
@resolvers.each do |arg,resolvers|
|
34
|
+
if args.key? arg
|
35
|
+
value = args[arg]
|
36
36
|
|
37
37
|
resolvers.each do |method, params|
|
38
38
|
# Match scopes
|
@@ -62,16 +62,20 @@ module GraphQL
|
|
62
62
|
raise ArgumentError, "Unable to resolve parameter of type #{method.class} in #{self}"
|
63
63
|
end
|
64
64
|
elsif params.size < 1
|
65
|
-
if
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
if is_arg_id_type? arg
|
66
|
+
value = resolve_id(value)
|
67
|
+
end
|
68
|
+
|
69
|
+
if self.respond_to? arg and params[:where].present? == false
|
70
|
+
@result = send(arg, value)
|
71
|
+
elsif @result.respond_to? arg and params[:where].present? == false
|
72
|
+
@result = @result.send(arg, value)
|
69
73
|
else
|
70
74
|
attribute =
|
71
75
|
if params[:where].present?
|
72
76
|
params[:where]
|
73
77
|
else
|
74
|
-
|
78
|
+
arg
|
75
79
|
end
|
76
80
|
|
77
81
|
hash = {}
|
@@ -79,7 +83,7 @@ module GraphQL
|
|
79
83
|
@result = @result.where(hash)
|
80
84
|
end
|
81
85
|
else
|
82
|
-
raise ArgumentError, "Unable to resolve
|
86
|
+
raise ArgumentError, "Unable to resolve argument #{arg} in #{self}"
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
@@ -107,12 +111,11 @@ module GraphQL
|
|
107
111
|
@ctx.ast_node.name
|
108
112
|
end
|
109
113
|
|
110
|
-
def has_id_argument
|
114
|
+
def has_id_argument?
|
111
115
|
@ctx.irep_node.definitions.any? do |type_defn, field_defn|
|
112
116
|
if field_defn.name === field_name
|
113
117
|
field_defn.arguments.any? do |k,v|
|
114
|
-
v.type
|
115
|
-
(v.type.kind == ::GraphQL::TypeKinds::LIST and v.type.of_type == ::GraphQL::ID_TYPE)
|
118
|
+
is_field_id_type?(v.type)
|
116
119
|
end
|
117
120
|
else
|
118
121
|
false
|
@@ -120,9 +123,14 @@ module GraphQL
|
|
120
123
|
end
|
121
124
|
end
|
122
125
|
|
126
|
+
def has_id_argument
|
127
|
+
warn "[DEPRECATION] `has_id_argument` is deprecated. Please use `has_id_argument?` instead."
|
128
|
+
has_id_argument?
|
129
|
+
end
|
130
|
+
|
123
131
|
def has_id_field
|
124
132
|
warn "[DEPRECATION] `has_id_field` is deprecated. Please use `has_id_argument` instead."
|
125
|
-
has_id_argument
|
133
|
+
has_id_argument?
|
126
134
|
end
|
127
135
|
|
128
136
|
def connection?
|
@@ -133,6 +141,24 @@ module GraphQL
|
|
133
141
|
@ctx.irep_node.definitions.all? { |type_defn, field_defn| field_defn.type.kind.eql?(GraphQL::TypeKinds::LIST) }
|
134
142
|
end
|
135
143
|
|
144
|
+
def get_field_args
|
145
|
+
@ctx.irep_node.parent.return_type.get_field(@ctx.irep_node.definition_name).arguments
|
146
|
+
end
|
147
|
+
|
148
|
+
def get_arg_type(key)
|
149
|
+
args = get_field_args
|
150
|
+
args[key].type
|
151
|
+
end
|
152
|
+
|
153
|
+
def is_field_id_type?(field)
|
154
|
+
field == ::GraphQL::ID_TYPE or
|
155
|
+
(field.kind == ::GraphQL::TypeKinds::LIST and field.of_type == ::GraphQL::ID_TYPE)
|
156
|
+
end
|
157
|
+
|
158
|
+
def is_arg_id_type?(key)
|
159
|
+
is_field_id_type?(get_arg_type(key))
|
160
|
+
end
|
161
|
+
|
136
162
|
def model
|
137
163
|
unless self.class < Resolvers::Base
|
138
164
|
raise ArgumentError, "Cannot call `model` on BaseResolver"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-rails-resolver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cole Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|