graphql-rails 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/rails.rb +1 -0
- data/lib/graphql/rails/fields.rb +11 -0
- data/lib/graphql/rails/operations.rb +21 -8
- data/lib/graphql/rails/schema.rb +0 -1
- data/lib/graphql/rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 057f13274ec2fa2303ce2a0e8c9cfc5a9aa9be78
|
4
|
+
data.tar.gz: 0a33325845d6af90994ad94e164e6f1a56fa14c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757acce6e810e6b54dfeb031803f1c84579fd5c628f85d95234b4a187e61333f4e08157fc3b2409be9c8868d09b4298d0c1dd57abe3f1bfa01e208a32a4132e2
|
7
|
+
data.tar.gz: 5b61fef40d244b6971086d7c431d640ed5fbc34c57886e1dd526a69140aee0edb2b77839efe106e82632bd5743d1fcb1aa9bb4cdee09c520d7c03b3390547d9d
|
data/lib/graphql/rails.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
module GraphQL
|
2
|
+
module Rails
|
3
|
+
# Object that transforms key lookups on an object to the active field
|
4
|
+
# naming convention, delegating all remaining methods as-is.
|
5
|
+
class Fields < SimpleDelegator
|
6
|
+
def [](key)
|
7
|
+
__getobj__[Types.to_field_name(key)]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -62,7 +62,7 @@ module GraphQL
|
|
62
62
|
def self.mutation(hash, &block)
|
63
63
|
hash = extract_pair(hash)
|
64
64
|
unless hash[:type].is_a?(Hash)
|
65
|
-
raise '
|
65
|
+
raise 'Mutation must be specified with a Hash result type'
|
66
66
|
end
|
67
67
|
Rails.logger.debug "Adding mutation: #{Types.to_field_name(hash[:name])}"
|
68
68
|
|
@@ -112,11 +112,11 @@ module GraphQL
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def resolve(&block)
|
115
|
-
field.resolve = -> (obj, args, ctx) do
|
115
|
+
@field.resolve = -> (obj, args, ctx) do
|
116
116
|
# Instantiate the Operations class with state on this query.
|
117
117
|
instance = @klass.new({
|
118
118
|
op: :query, name: @name, type: @type,
|
119
|
-
obj: obj, args: args, ctx: ctx, context: ctx
|
119
|
+
obj: obj, args: Fields.new(args), ctx: ctx, context: ctx
|
120
120
|
})
|
121
121
|
|
122
122
|
begin
|
@@ -165,8 +165,9 @@ module GraphQL
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def field
|
168
|
+
# Build input object according to mutation specification.
|
168
169
|
input = @input
|
169
|
-
input.name = "#{@
|
170
|
+
input.name = "#{@name.to_s.camelize(:upper)}Input"
|
170
171
|
input.description = "Generated input type for #{@field.name}"
|
171
172
|
input.arguments['clientMutationId'] = ::GraphQL::Argument.define do
|
172
173
|
name 'clientMutationId'
|
@@ -174,8 +175,9 @@ module GraphQL
|
|
174
175
|
description 'Unique identifier for client performing mutation'
|
175
176
|
end
|
176
177
|
|
178
|
+
# Build compound output object according to mutation specification.
|
177
179
|
output = @output
|
178
|
-
output.name = "#{@
|
180
|
+
output.name = "#{@name.to_s.camelize(:upper)}Output"
|
179
181
|
output.description = "Generated output type for #{@field.name}"
|
180
182
|
output.fields['clientMutationId'] = ::GraphQL::Field.define do
|
181
183
|
name 'clientMutationId'
|
@@ -192,11 +194,11 @@ module GraphQL
|
|
192
194
|
end
|
193
195
|
|
194
196
|
def resolve(&block)
|
195
|
-
field.resolve = -> (obj, args, ctx) do
|
197
|
+
@field.resolve = -> (obj, args, ctx) do
|
196
198
|
# Instantiate the Operations class with state on this query.
|
197
199
|
instance = @klass.new({
|
198
200
|
op: :mutation, name: @name, type: @type,
|
199
|
-
obj: obj, args: args[:input], ctx: ctx, context: ctx
|
201
|
+
obj: obj, args: Fields.new(args[:input]), ctx: ctx, context: ctx
|
200
202
|
})
|
201
203
|
|
202
204
|
begin
|
@@ -204,7 +206,18 @@ module GraphQL
|
|
204
206
|
instance.run_callbacks(:perform_operation) do
|
205
207
|
# Call out to the app-defined resolver.
|
206
208
|
result = instance.instance_eval(&block)
|
207
|
-
|
209
|
+
|
210
|
+
# Transform the result keys to the expected convention.
|
211
|
+
unless result.is_a?(::Hash)
|
212
|
+
raise 'Mutation must resolve to a Hash result'
|
213
|
+
end
|
214
|
+
|
215
|
+
result = result.inject({
|
216
|
+
'clientMutationId' => args['clientMutationId']
|
217
|
+
}) do |hash, (key, value)|
|
218
|
+
hash[Types.to_field_name(key)] = value
|
219
|
+
hash
|
220
|
+
end
|
208
221
|
::OpenStruct.new(result)
|
209
222
|
end
|
210
223
|
rescue => e
|
data/lib/graphql/rails/schema.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Reggio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/graphql/rails/engine.rb
|
105
105
|
- lib/graphql/rails/extensions/cancan.rb
|
106
106
|
- lib/graphql/rails/extensions/mongoid.rb
|
107
|
+
- lib/graphql/rails/fields.rb
|
107
108
|
- lib/graphql/rails/node_identification.rb
|
108
109
|
- lib/graphql/rails/operations.rb
|
109
110
|
- lib/graphql/rails/schema.rb
|