Commit 78962710 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ajk-todos-return-resource' into 'master'

[GraphQL] Mutations should return the mutated resource

See merge request gitlab-org/gitlab!35998
parents eaea6a68 48f15853
...@@ -7,6 +7,8 @@ module Mutations ...@@ -7,6 +7,8 @@ module Mutations
ERROR_MESSAGE = 'You cannot perform write operations on a read-only instance' ERROR_MESSAGE = 'You cannot perform write operations on a read-only instance'
field_class ::Types::BaseField
field :errors, [GraphQL::STRING_TYPE], field :errors, [GraphQL::STRING_TYPE],
null: false, null: false,
description: 'Errors encountered during execution of the mutation.' description: 'Errors encountered during execution of the mutation.'
......
...@@ -10,8 +10,13 @@ module Mutations ...@@ -10,8 +10,13 @@ module Mutations
field :updated_ids, field :updated_ids,
[GraphQL::ID_TYPE], [GraphQL::ID_TYPE],
null: false, null: false,
deprecated: { reason: 'Use todos', milestone: '13.2' },
description: 'Ids of the updated todos' description: 'Ids of the updated todos'
field :todos, [::Types::TodoType],
null: false,
description: 'Updated todos'
def resolve def resolve
authorize!(current_user) authorize!(current_user)
...@@ -19,6 +24,7 @@ module Mutations ...@@ -19,6 +24,7 @@ module Mutations
{ {
updated_ids: map_to_global_ids(updated_ids), updated_ids: map_to_global_ids(updated_ids),
todos: Todo.id_in(updated_ids),
errors: [] errors: []
} }
end end
......
...@@ -14,7 +14,12 @@ module Mutations ...@@ -14,7 +14,12 @@ module Mutations
field :updated_ids, [GraphQL::ID_TYPE], field :updated_ids, [GraphQL::ID_TYPE],
null: false, null: false,
description: 'The ids of the updated todo items' description: 'The ids of the updated todo items',
deprecated: { reason: 'Use todos', milestone: '13.2' }
field :todos, [::Types::TodoType],
null: false,
description: 'Updated todos'
def resolve(ids:) def resolve(ids:)
check_update_amount_limit!(ids) check_update_amount_limit!(ids)
...@@ -24,6 +29,7 @@ module Mutations ...@@ -24,6 +29,7 @@ module Mutations
{ {
updated_ids: gids_of(updated_ids), updated_ids: gids_of(updated_ids),
todos: Todo.id_in(updated_ids),
errors: errors_on_objects(todos) errors: errors_on_objects(todos)
} }
end end
......
---
title: Todo Mutations should return the mutated todos
merge_request: 35998
author:
type: added
...@@ -13129,9 +13129,14 @@ type TodoRestoreManyPayload { ...@@ -13129,9 +13129,14 @@ type TodoRestoreManyPayload {
errors: [String!]! errors: [String!]!
""" """
The ids of the updated todo items Updated todos
""" """
updatedIds: [ID!]! todos: [Todo!]!
"""
The ids of the updated todo items. Deprecated in 13.2: Use todos
"""
updatedIds: [ID!]! @deprecated(reason: "Use todos. Deprecated in 13.2")
} }
""" """
...@@ -13211,9 +13216,14 @@ type TodosMarkAllDonePayload { ...@@ -13211,9 +13216,14 @@ type TodosMarkAllDonePayload {
errors: [String!]! errors: [String!]!
""" """
Ids of the updated todos Updated todos
"""
todos: [Todo!]!
"""
Ids of the updated todos. Deprecated in 13.2: Use todos
""" """
updatedIds: [ID!]! updatedIds: [ID!]! @deprecated(reason: "Use todos. Deprecated in 13.2")
} }
""" """
......
...@@ -38784,9 +38784,35 @@ ...@@ -38784,9 +38784,35 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "todos",
"description": "Updated todos",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Todo",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "updatedIds", "name": "updatedIds",
"description": "The ids of the updated todo items", "description": "The ids of the updated todo items. Deprecated in 13.2: Use todos",
"args": [ "args": [
], ],
...@@ -38807,8 +38833,8 @@ ...@@ -38807,8 +38833,8 @@
} }
} }
}, },
"isDeprecated": false, "isDeprecated": true,
"deprecationReason": null "deprecationReason": "Use todos. Deprecated in 13.2"
} }
], ],
"inputFields": null, "inputFields": null,
...@@ -39019,9 +39045,35 @@ ...@@ -39019,9 +39045,35 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "todos",
"description": "Updated todos",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Todo",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "updatedIds", "name": "updatedIds",
"description": "Ids of the updated todos", "description": "Ids of the updated todos. Deprecated in 13.2: Use todos",
"args": [ "args": [
], ],
...@@ -39042,8 +39094,8 @@ ...@@ -39042,8 +39094,8 @@
} }
} }
}, },
"isDeprecated": false, "isDeprecated": true,
"deprecationReason": null "deprecationReason": "Use todos. Deprecated in 13.2"
} }
], ],
"inputFields": null, "inputFields": null,
...@@ -1968,7 +1968,8 @@ Autogenerated return type of TodoRestoreMany ...@@ -1968,7 +1968,8 @@ Autogenerated return type of TodoRestoreMany
| --- | ---- | ---------- | | --- | ---- | ---------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. | | `clientMutationId` | String | A unique identifier for the client performing the mutation. |
| `errors` | String! => Array | Errors encountered during execution of the mutation. | | `errors` | String! => Array | Errors encountered during execution of the mutation. |
| `updatedIds` | ID! => Array | The ids of the updated todo items | | `todos` | Todo! => Array | Updated todos |
| `updatedIds` **{warning-solid}** | ID! => Array | **Deprecated:** Use todos. Deprecated in 13.2 |
## TodoRestorePayload ## TodoRestorePayload
...@@ -1988,7 +1989,8 @@ Autogenerated return type of TodosMarkAllDone ...@@ -1988,7 +1989,8 @@ Autogenerated return type of TodosMarkAllDone
| --- | ---- | ---------- | | --- | ---- | ---------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. | | `clientMutationId` | String | A unique identifier for the client performing the mutation. |
| `errors` | String! => Array | Errors encountered during execution of the mutation. | | `errors` | String! => Array | Errors encountered during execution of the mutation. |
| `updatedIds` | ID! => Array | Ids of the updated todos | | `todos` | Todo! => Array | Updated todos |
| `updatedIds` **{warning-solid}** | ID! => Array | **Deprecated:** Use todos. Deprecated in 13.2 |
## ToggleAwardEmojiPayload ## ToggleAwardEmojiPayload
......
...@@ -21,7 +21,7 @@ RSpec.describe Mutations::Todos::MarkAllDone do ...@@ -21,7 +21,7 @@ RSpec.describe Mutations::Todos::MarkAllDone do
describe '#resolve' do describe '#resolve' do
it 'marks all pending todos as done' do it 'marks all pending todos as done' do
updated_todo_ids = mutation_for(current_user).resolve.dig(:updated_ids) updated_todo_ids, todos = mutation_for(current_user).resolve.values_at(:updated_ids, :todos)
expect(todo1.reload.state).to eq('done') expect(todo1.reload.state).to eq('done')
expect(todo2.reload.state).to eq('done') expect(todo2.reload.state).to eq('done')
...@@ -29,6 +29,7 @@ RSpec.describe Mutations::Todos::MarkAllDone do ...@@ -29,6 +29,7 @@ RSpec.describe Mutations::Todos::MarkAllDone do
expect(other_user_todo.reload.state).to eq('pending') expect(other_user_todo.reload.state).to eq('pending')
expect(updated_todo_ids).to contain_exactly(global_id_of(todo1), global_id_of(todo3)) expect(updated_todo_ids).to contain_exactly(global_id_of(todo1), global_id_of(todo3))
expect(todos).to contain_exactly(todo1, todo3)
end end
it 'behaves as expected if there are no todos for the requesting user' do it 'behaves as expected if there are no todos for the requesting user' do
......
...@@ -25,6 +25,8 @@ RSpec.describe Mutations::Todos::RestoreMany do ...@@ -25,6 +25,8 @@ RSpec.describe Mutations::Todos::RestoreMany do
todo_ids = result[:updated_ids] todo_ids = result[:updated_ids]
expect(todo_ids.size).to eq(1) expect(todo_ids.size).to eq(1)
expect(todo_ids.first).to eq(todo1.to_global_id.to_s) expect(todo_ids.first).to eq(todo1.to_global_id.to_s)
expect(result[:todos]).to contain_exactly(todo1)
end end
it 'handles a todo which is already pending as expected' do it 'handles a todo which is already pending as expected' do
...@@ -33,6 +35,7 @@ RSpec.describe Mutations::Todos::RestoreMany do ...@@ -33,6 +35,7 @@ RSpec.describe Mutations::Todos::RestoreMany do
expect_states_were_not_changed expect_states_were_not_changed
expect(result[:updated_ids]).to eq([]) expect(result[:updated_ids]).to eq([])
expect(result[:todos]).to be_empty
end end
it 'ignores requests for todos which do not belong to the current user' do it 'ignores requests for todos which do not belong to the current user' do
...@@ -56,6 +59,7 @@ RSpec.describe Mutations::Todos::RestoreMany do ...@@ -56,6 +59,7 @@ RSpec.describe Mutations::Todos::RestoreMany do
returned_todo_ids = result[:updated_ids] returned_todo_ids = result[:updated_ids]
expect(returned_todo_ids).to contain_exactly(todo1.to_global_id.to_s, todo4.to_global_id.to_s) expect(returned_todo_ids).to contain_exactly(todo1.to_global_id.to_s, todo4.to_global_id.to_s)
expect(result[:todos]).to contain_exactly(todo1, todo4)
expect(todo1.reload.state).to eq('pending') expect(todo1.reload.state).to eq('pending')
expect(todo2.reload.state).to eq('pending') expect(todo2.reload.state).to eq('pending')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment