Skip to content
This repository was archived by the owner on Sep 24, 2019. It is now read-only.

Commit 3196c8d

Browse files
committed
Return Rating in payload
1 parent 75a9704 commit 3196c8d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

app/models/graph/mutations/film_rate.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module Mutations
66
input_field :filmId, !types.ID
77
input_field :rating, !types.Int
88

9-
return_field :film, Graph::Types::Film
9+
return_field :film, !Graph::Types::Film
10+
return_field :rating, Graph::Types::Rating
1011
return_field :errors, !types[!Graph::Types::MutationError]
1112

1213
resolve ->(_, input, ctx) do
@@ -22,11 +23,13 @@ module Mutations
2223
if rating.save
2324
{
2425
film: film,
26+
rating: rating,
2527
errors: []
2628
}
2729
else
2830
{
2931
film: film,
32+
rating: nil,
3033
errors: rating.errors.map { |field, message| MutationError.new(field, message) },
3134
}
3235
end

test/models/graph/mutations/film_rate_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def setup
1212
film {
1313
title
1414
}
15+
rating {
16+
rating
17+
}
1518
errors {
1619
field
1720
message
@@ -67,6 +70,7 @@ def setup
6770
"film" => {
6871
"title" => @film.title
6972
},
73+
"rating" => nil,
7074
"errors" => [
7175
{ "field" => "rating", "message" => "must be less than or equal to 5" }
7276
]
@@ -85,6 +89,9 @@ def setup
8589
"film" => {
8690
"title" => @film.title
8791
},
92+
"rating" => {
93+
"rating" => 5
94+
},
8895
"errors" => [],
8996
}
9097
}
@@ -108,6 +115,9 @@ def setup
108115
"film" => {
109116
"title" => @film.title
110117
},
118+
"rating" => {
119+
"rating" => 5
120+
},
111121
"errors" => [],
112122
}
113123
}

0 commit comments

Comments
 (0)