Commit 9f7b0539 authored by Max Woolf's avatar Max Woolf

Merge branch '32081-design-rich-data' into 'master'

Add fields to graphQL version type

See merge request gitlab-org/gitlab!61567
parents 5239601b 09372d2b
......@@ -62,6 +62,7 @@ module Resolvers
::DesignManagement::VersionsFinder
.new(design_or_collection, current_user, params)
.execute
.with_author
end
def by_id(gid)
......
......@@ -32,6 +32,10 @@ module Types
null: false,
description: 'A particular design as of this version, provided it is visible at this version.',
resolver: ::Resolvers::DesignManagement::Version::DesignsAtVersionResolver.single
field :author, Types::UserType, null: false, description: 'Author of the version.'
field :created_at, Types::TimeType, null: false,
description: 'Timestamp of when the version was created.'
end
end
end
......@@ -58,6 +58,7 @@ module DesignManagement
scope :ordered, -> { order(id: :desc) }
scope :for_issue, -> (issue) { where(issue: issue) }
scope :by_sha, -> (sha) { where(sha: sha) }
scope :with_author, -> { includes(:author) }
# This is the one true way to create a Version.
#
......
---
title: Add fields to graphQL version type
merge_request: 61567
author:
type: added
......@@ -8024,6 +8024,8 @@ A specific version in which designs were added, modified or deleted.
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="designversionauthor"></a>`author` | [`UserCore!`](#usercore) | Author of the version. |
| <a id="designversioncreatedat"></a>`createdAt` | [`Time!`](#time) | Timestamp of when the version was created. |
| <a id="designversiondesigns"></a>`designs` | [`DesignConnection!`](#designconnection) | All designs that were changed in the version. (see [Connections](#connections)) |
| <a id="designversionid"></a>`id` | [`ID!`](#id) | ID of the design version. |
| <a id="designversionsha"></a>`sha` | [`ID!`](#id) | SHA of the design version. |
......
......@@ -41,6 +41,20 @@ RSpec.describe Resolvers::DesignManagement::VersionsResolver do
it 'returns the ordered versions' do
expect(result.to_a).to eq(all_versions)
end
context 'loading associations' do
it 'prevents N+1 queries when loading author' do
control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
resolve_versions(object).items.map(&:author)
end.count
create_list(:design_version, 3, issue: issue)
expect do
resolve_versions(object).items.map(&:author)
end.not_to exceed_all_query_limit(control_count)
end
end
end
context 'when constrained' do
......
......@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['DesignVersion'] do
it { expect(described_class).to require_graphql_authorizations(:read_design) }
it 'has the expected fields' do
expected_fields = %i[id sha designs design_at_version designs_at_version]
expected_fields = %i[id sha designs design_at_version designs_at_version author created_at]
expect(described_class).to have_graphql_fields(*expected_fields)
end
......
......@@ -33,6 +33,7 @@ RSpec.describe 'Getting versions related to an issue' do
let(:version_params) { nil }
let(:version_query_fields) { ['edges { node { sha } }'] }
let(:edges_path) { %w[project issue designCollection versions edges] }
let(:project) { issue.project }
let(:current_user) { owner }
......@@ -50,8 +51,7 @@ RSpec.describe 'Getting versions related to an issue' do
end
def response_values(data = graphql_data, key = 'sha')
path = %w[project issue designCollection versions edges]
data.dig(*path).map { |e| e.dig('node', key) }
data.dig(*edges_path).map { |e| e.dig('node', key) }
end
before do
......@@ -64,6 +64,19 @@ RSpec.describe 'Getting versions related to an issue' do
expect(response_values).to match_array([version_a, version_b, version_c, version_d].map(&:sha))
end
context 'with all fields requested' do
let(:version_query_fields) do
['edges { node { id sha createdAt author { id } } }']
end
it 'returns correct data' do
post_graphql(query, current_user: current_user)
keys = graphql_data.dig(*edges_path).first['node'].keys
expect(keys).to match_array(%w(id sha createdAt author))
end
end
describe 'filter by sha' do
let(:sha) { version_b.sha }
......
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