Commit 55cb93cc authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '227668-boards_resolver_id_required' into 'master'

Add GraphQL BoardResolver

Closes #227668

See merge request gitlab-org/gitlab!43627
parents 83624bde 0c623080
# frozen_string_literal: true
module Resolvers
class BoardResolver < BaseResolver.single
alias_method :parent, :synchronized_object
type Types::BoardType, null: true
argument :id, GraphQL::ID_TYPE,
required: true,
description: 'The board\'s ID'
def resolve(id: nil)
return unless parent
::Boards::ListService.new(parent, context[:current_user], board_id: extract_board_id(id)).execute(create_default_board: false).first
rescue ActiveRecord::RecordNotFound
nil
end
private
def extract_board_id(gid)
GitlabSchema.parse_gid(gid, expected_type: ::Board).model_id
end
end
end
......@@ -64,7 +64,7 @@ module Types
Types::BoardType,
null: true,
description: 'A single board of the group',
resolver: Resolvers::BoardsResolver.single
resolver: Resolvers::BoardResolver
field :label,
Types::LabelType,
......
......@@ -234,7 +234,7 @@ module Types
Types::BoardType,
null: true,
description: 'A single board of the project',
resolver: Resolvers::BoardsResolver.single
resolver: Resolvers::BoardResolver
field :jira_imports,
Types::JiraImportType.connection_type,
......
---
title: 'GraphQL: No longer allows to omit ID when querying for a single board.'
merge_request: 43627
author:
type: fixed
......@@ -7125,9 +7125,9 @@ type Group {
"""
board(
"""
Find a board by its ID
The board's ID
"""
id: ID
id: ID!
): Board
"""
......@@ -12761,9 +12761,9 @@ type Project {
"""
board(
"""
Find a board by its ID
The board's ID
"""
id: ID
id: ID!
): Board
"""
......
......@@ -19764,11 +19764,15 @@
"args": [
{
"name": "id",
"description": "Find a board by its ID",
"description": "The board's ID",
"type": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
}
......@@ -37719,11 +37723,15 @@
"args": [
{
"name": "id",
"description": "Find a board by its ID",
"description": "The board's ID",
"type": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
}
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::BoardResolver do
include GraphqlHelpers
let_it_be(:user) { create(:user) }
let(:dummy_gid) { 'gid://gitlab/Board/1' }
shared_examples_for 'group and project boards resolver' do
it 'does not create a default board' do
expect(resolve_board(id: dummy_gid)).to eq nil
end
it 'calls Boards::ListService' do
expect_next_instance_of(Boards::ListService) do |service|
expect(service).to receive(:execute).and_return([])
end
resolve_board(id: dummy_gid)
end
it 'requires an ID' do
expect do
resolve(described_class, obj: board_parent, args: {}, ctx: { current_user: user })
end.to raise_error(Gitlab::Graphql::Errors::ArgumentError)
end
context 'when querying for a single board' do
let(:board1) { create(:board, name: 'One', resource_parent: board_parent) }
it 'returns specified board' do
expect(resolve_board(id: global_id_of(board1))).to eq board1
end
it 'returns nil if board not found' do
outside_parent = create(board_parent.class.underscore.to_sym) # rubocop:disable Rails/SaveBang
outside_board = create(:board, name: 'outside board', resource_parent: outside_parent)
expect(resolve_board(id: global_id_of(outside_board))).to eq nil
end
end
end
describe '#resolve' do
context 'when there is no parent' do
let(:board_parent) { nil }
it 'returns nil if parent is nil' do
expect(resolve_board(id: dummy_gid)).to eq(nil)
end
end
context 'when project boards' do
let(:board_parent) { create(:project, :public, creator_id: user.id, namespace: user.namespace ) }
it_behaves_like 'group and project boards resolver'
end
context 'when group boards' do
let(:board_parent) { create(:group) }
it_behaves_like 'group and project boards resolver'
end
end
def resolve_board(id:)
resolve(described_class, obj: board_parent, args: { id: id }, ctx: { current_user: user })
end
end
......@@ -90,7 +90,7 @@ RSpec.shared_examples 'group and project boards query' do
it_behaves_like 'a working graphql query' do
before do
post_graphql(query_single_board, current_user: current_user)
post_graphql(query_single_board("id: \"gid://gitlab/Board/1\""), current_user: current_user)
end
end
......
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