graphql 1.5.12 → 1.5.13
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68f3728c4d164599a943599551db20d7add67e5d
|
4
|
+
data.tar.gz: 86b930739f630566edbaeb9b024e6461f5a30627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdaf08df4286ec916b87839a354eb7d21bf822d49462a659a5e634210065baac1a5553a3dec3003b6c24bd5c8f4ab894f0796603883d4f87d7024ddffef87ece
|
7
|
+
data.tar.gz: b64f7d422547af515ee634f885dd6f5fc990478ef84c65e5bd244e8b889fb206ae7aa4843309723a8ab2a9baf47cf01a30226b4c6bb6c2b952d298b0cb120942
|
@@ -11,8 +11,8 @@ module GraphQL
|
|
11
11
|
# giving users access to the original resolve function in earlier instrumentation.
|
12
12
|
def self.instrument(type, field)
|
13
13
|
if field.mutation
|
14
|
-
new_resolve = Mutation::Resolve.new(field.mutation, field.resolve_proc)
|
15
|
-
new_lazy_resolve = Mutation::Resolve.new(field.mutation, field.lazy_resolve_proc)
|
14
|
+
new_resolve = Mutation::Resolve.new(field.mutation, field.resolve_proc, eager: true)
|
15
|
+
new_lazy_resolve = Mutation::Resolve.new(field.mutation, field.lazy_resolve_proc, eager: false)
|
16
16
|
field.redefine(resolve: new_resolve, lazy_resolve: new_lazy_resolve)
|
17
17
|
else
|
18
18
|
field
|
@@ -7,35 +7,40 @@ module GraphQL
|
|
7
7
|
# Also, pass the `clientMutationId` to that result object.
|
8
8
|
# @api private
|
9
9
|
class Resolve
|
10
|
-
def initialize(mutation, resolve)
|
10
|
+
def initialize(mutation, resolve, eager:)
|
11
11
|
@mutation = mutation
|
12
12
|
@resolve = resolve
|
13
13
|
@wrap_result = mutation.has_generated_return_type?
|
14
|
+
@eager = eager
|
14
15
|
end
|
15
16
|
|
16
17
|
def call(obj, args, ctx)
|
18
|
+
error_raised = false
|
17
19
|
begin
|
18
20
|
mutation_result = @resolve.call(obj, args[:input], ctx)
|
19
21
|
rescue GraphQL::ExecutionError => err
|
20
22
|
mutation_result = err
|
23
|
+
error_raised = true
|
21
24
|
end
|
22
25
|
|
23
26
|
if ctx.schema.lazy?(mutation_result)
|
24
27
|
mutation_result
|
25
28
|
else
|
26
|
-
build_result(mutation_result, args, ctx)
|
29
|
+
build_result(mutation_result, args, ctx, raised: error_raised)
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
31
34
|
|
32
|
-
def build_result(mutation_result, args, ctx)
|
35
|
+
def build_result(mutation_result, args, ctx, raised: false)
|
33
36
|
if mutation_result.is_a?(GraphQL::ExecutionError)
|
34
37
|
ctx.add_error(mutation_result)
|
35
38
|
mutation_result = nil
|
36
39
|
end
|
37
40
|
|
38
|
-
if @
|
41
|
+
if @eager && raised
|
42
|
+
nil
|
43
|
+
elsif @wrap_result
|
39
44
|
if mutation_result && !mutation_result.is_a?(Hash)
|
40
45
|
raise StandardError, "Expected `#{mutation_result}` to be a Hash."\
|
41
46
|
" Return a hash when using `return_field` or specify a custom `return_type`."
|
data/lib/graphql/version.rb
CHANGED
@@ -322,5 +322,24 @@ describe GraphQL::Relay::Mutation do
|
|
322
322
|
|
323
323
|
assert_equal(expected, result)
|
324
324
|
end
|
325
|
+
|
326
|
+
it "supports raising an error in the resolve function" do
|
327
|
+
result = star_wars_query(query_string, "clientMutationId" => "5678", "shipName" => "Leviathan")
|
328
|
+
|
329
|
+
expected = {
|
330
|
+
"data" => {
|
331
|
+
"introduceShip" => nil,
|
332
|
+
},
|
333
|
+
"errors" => [
|
334
|
+
{
|
335
|
+
"message" => "🔥",
|
336
|
+
"locations" => [ { "line" => 3 , "column" => 7}],
|
337
|
+
"path" => ["introduceShip"]
|
338
|
+
}
|
339
|
+
]
|
340
|
+
}
|
341
|
+
|
342
|
+
assert_equal(expected, result)
|
343
|
+
end
|
325
344
|
end
|
326
345
|
end
|
@@ -209,6 +209,8 @@ module StarWars
|
|
209
209
|
faction_id = args["factionId"]
|
210
210
|
if args["shipName"] == 'Millennium Falcon'
|
211
211
|
GraphQL::ExecutionError.new("Sorry, Millennium Falcon ship is reserved")
|
212
|
+
elsif args["shipName"] == 'Leviathan'
|
213
|
+
raise GraphQL::ExecutionError.new("🔥")
|
212
214
|
elsif args["shipName"] == "Ebon Hawk"
|
213
215
|
LazyWrapper.new { raise GraphQL::ExecutionError.new("💥")}
|
214
216
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -642,7 +642,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
642
642
|
version: '0'
|
643
643
|
requirements: []
|
644
644
|
rubyforge_project:
|
645
|
-
rubygems_version: 2.6.
|
645
|
+
rubygems_version: 2.6.11
|
646
646
|
signing_key:
|
647
647
|
specification_version: 4
|
648
648
|
summary: A GraphQL language and runtime for Ruby
|