Commit cc152518 authored by James Lopez's avatar James Lopez

Merge branch '207278-graphql-upgrade-to-graphql-ruby-1-10' into 'master'

GraphQL: Upgrade to GraphQL-Ruby 1.10

Closes #207278

See merge request gitlab-org/gitlab!26096
parents ee0c3cc7 846ef5c2
...@@ -87,7 +87,7 @@ gem 'grape-entity', '~> 0.7.1' ...@@ -87,7 +87,7 @@ gem 'grape-entity', '~> 0.7.1'
gem 'rack-cors', '~> 1.0.6', require: 'rack/cors' gem 'rack-cors', '~> 1.0.6', require: 'rack/cors'
# GraphQL API # GraphQL API
gem 'graphql', '~> 1.9.19' gem 'graphql', '~> 1.10.5'
# NOTE: graphiql-rails v1.5+ doesn't work: https://gitlab.com/gitlab-org/gitlab/issues/31771 # NOTE: graphiql-rails v1.5+ doesn't work: https://gitlab.com/gitlab-org/gitlab/issues/31771
# TODO: remove app/views/graphiql/rails/editors/show.html.erb when https://github.com/rmosolgo/graphiql-rails/pull/71 is released: # TODO: remove app/views/graphiql/rails/editors/show.html.erb when https://github.com/rmosolgo/graphiql-rails/pull/71 is released:
# https://gitlab.com/gitlab-org/gitlab/issues/31747 # https://gitlab.com/gitlab-org/gitlab/issues/31747
......
...@@ -456,7 +456,7 @@ GEM ...@@ -456,7 +456,7 @@ GEM
graphiql-rails (1.4.10) graphiql-rails (1.4.10)
railties railties
sprockets-rails sprockets-rails
graphql (1.9.19) graphql (1.10.5)
graphql-docs (1.6.0) graphql-docs (1.6.0)
commonmarker (~> 0.16) commonmarker (~> 0.16)
escape_utils (~> 1.2) escape_utils (~> 1.2)
...@@ -1252,7 +1252,7 @@ DEPENDENCIES ...@@ -1252,7 +1252,7 @@ DEPENDENCIES
grape-path-helpers (~> 1.2) grape-path-helpers (~> 1.2)
grape_logging (~> 1.7) grape_logging (~> 1.7)
graphiql-rails (~> 1.4.10) graphiql-rails (~> 1.4.10)
graphql (~> 1.9.19) graphql (~> 1.10.5)
graphql-docs (~> 1.6.0) graphql-docs (~> 1.6.0)
grpc (~> 1.24.0) grpc (~> 1.24.0)
gssapi gssapi
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
require 'spec_helper' require 'spec_helper'
# describe GitlabSchema.types['DesignAtVersion'] do describe GitlabSchema.types['DesignAtVersion'] do
# This not available on the schema until we mount it somewhere
describe ::Types::DesignManagement::DesignAtVersionType.to_graphql do
it_behaves_like 'a GraphQL type with design fields' do it_behaves_like 'a GraphQL type with design fields' do
let(:extra_design_fields) { %i[version design] } let(:extra_design_fields) { %i[version design] }
let_it_be(:design) { create(:design, :with_versions) } let_it_be(:design) { create(:design, :with_versions) }
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
require 'spec_helper' require 'spec_helper'
describe GitlabSchema.types['DesignManagement'] do describe GitlabSchema.types['DesignManagement'] do
it { is_expected.to have_graphql_fields(:version, :design_at_version) } it { expect(described_class).to have_graphql_fields(:version, :design_at_version) }
end end
...@@ -23,7 +23,7 @@ describe GitlabSchema.types['Epic'] do ...@@ -23,7 +23,7 @@ describe GitlabSchema.types['Epic'] do
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
it { is_expected.to have_graphql_field(:subscribed, complexity: 5) } it { expect(described_class).to have_graphql_field(:subscribed, complexity: 5) }
it { is_expected.to have_graphql_field(:participants, complexity: 5) } it { expect(described_class).to have_graphql_field(:participants, complexity: 5) }
end end
...@@ -6,7 +6,7 @@ describe GitlabSchema.types['Project'] do ...@@ -6,7 +6,7 @@ describe GitlabSchema.types['Project'] do
it 'includes the ee specific fields' do it 'includes the ee specific fields' do
expected_fields = %w[service_desk_enabled service_desk_address vulnerabilities] expected_fields = %w[service_desk_enabled service_desk_address vulnerabilities]
is_expected.to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
end end
describe 'vulnerabilities' do describe 'vulnerabilities' do
......
...@@ -4,6 +4,6 @@ require 'spec_helper' ...@@ -4,6 +4,6 @@ require 'spec_helper'
describe GitlabSchema.types['Query'] do describe GitlabSchema.types['Query'] do
it do it do
is_expected.to have_graphql_fields(:design_management).at_least expect(described_class).to have_graphql_fields(:design_management).at_least
end end
end end
...@@ -90,7 +90,7 @@ describe 'Updating an epic tree' do ...@@ -90,7 +90,7 @@ describe 'Updating an epic tree' do
end end
it_behaves_like 'a mutation that returns top-level errors', it_behaves_like 'a mutation that returns top-level errors',
errors: ['Variable epicTreeReorderInput of type EpicTreeReorderInput! was provided invalid value for moved.relativePosition (Expected "invalid" to be one of: before, after)'] errors: ['Variable $epicTreeReorderInput of type EpicTreeReorderInput! was provided invalid value for moved.relativePosition (Expected "invalid" to be one of: before, after)']
end end
context 'when object being moved is not supported type' do context 'when object being moved is not supported type' do
......
...@@ -55,7 +55,7 @@ describe 'Setting weight of an issue' do ...@@ -55,7 +55,7 @@ describe 'Setting weight of an issue' do
let(:input) { { weight: "2" } } let(:input) { { weight: "2" } }
it 'raises invalid value error' do it 'raises invalid value error' do
error = "Variable issueSetWeightInput of type IssueSetWeightInput! was provided "\ error = "Variable $issueSetWeightInput of type IssueSetWeightInput! was provided "\
"invalid value for weight (Could not coerce value \"#{input[:weight]}\" to Int)" "invalid value for weight (Could not coerce value \"#{input[:weight]}\" to Int)"
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
......
...@@ -22,7 +22,7 @@ RSpec.shared_examples 'a GraphQL type with design fields' do ...@@ -22,7 +22,7 @@ RSpec.shared_examples 'a GraphQL type with design fields' do
notes_count notes_count
] + extra_design_fields ] + extra_design_fields
is_expected.to have_graphql_fields(*expected_fields).only expect(described_class).to have_graphql_fields(*expected_fields).only
end end
describe '#image' do describe '#image' do
...@@ -41,7 +41,7 @@ RSpec.shared_examples 'a GraphQL type with design fields' do ...@@ -41,7 +41,7 @@ RSpec.shared_examples 'a GraphQL type with design fields' do
end end
it 'resolves to the design image URL' do it 'resolves to the design image URL' do
image = field.resolve(instance, args, context) image = field.resolve_field(instance, args, context)
sha = design.versions.first.sha sha = design.versions.first.sha
url = ::Gitlab::Routing.url_helpers.project_design_management_designs_raw_image_url(design.project, design, sha) url = ::Gitlab::Routing.url_helpers.project_design_management_designs_raw_image_url(design.project, design, sha)
...@@ -67,10 +67,10 @@ RSpec.shared_examples 'a GraphQL type with design fields' do ...@@ -67,10 +67,10 @@ RSpec.shared_examples 'a GraphQL type with design fields' do
# = 10 # = 10
expect(instance).not_to eq(instance_b) # preload designs themselves. expect(instance).not_to eq(instance_b) # preload designs themselves.
expect do expect do
image_a = field.resolve(instance, args, context) image_a = field.resolve_field(instance, args, context)
image_b = field.resolve(instance, args, context) image_b = field.resolve_field(instance, args, context)
image_c = field.resolve(instance_b, args, context) image_c = field.resolve_field(instance_b, args, context)
image_d = field.resolve(instance_b, args, context) image_d = field.resolve_field(instance_b, args, context)
expect(image_a).to eq(image_b) expect(image_a).to eq(image_b)
expect(image_c).not_to eq(image_b) expect(image_c).not_to eq(image_b)
expect(image_c).to eq(image_d) expect(image_c).to eq(image_d)
......
...@@ -9,7 +9,7 @@ describe 'Gitlab::Graphql::Authorization' do ...@@ -9,7 +9,7 @@ describe 'Gitlab::Graphql::Authorization' do
let(:permission_single) { :foo } let(:permission_single) { :foo }
let(:permission_collection) { [:foo, :bar] } let(:permission_collection) { [:foo, :bar] }
let(:test_object) { double(name: 'My name') } let(:test_object) { double(name: 'My name') }
let(:query_string) { '{ item() { name } }' } let(:query_string) { '{ item { name } }' }
let(:result) { execute_query(query_type)['data'] } let(:result) { execute_query(query_type)['data'] }
subject { result['item'] } subject { result['item'] }
...@@ -177,7 +177,7 @@ describe 'Gitlab::Graphql::Authorization' do ...@@ -177,7 +177,7 @@ describe 'Gitlab::Graphql::Authorization' do
end end
describe 'type authorizations when applied to a relay connection' do describe 'type authorizations when applied to a relay connection' do
let(:query_string) { '{ item() { edges { node { name } } } }' } let(:query_string) { '{ item { edges { node { name } } } }' }
let(:second_test_object) { double(name: 'Second thing') } let(:second_test_object) { double(name: 'Second thing') }
let(:type) do let(:type) do
......
...@@ -9,7 +9,7 @@ describe 'Graphql Field feature flags' do ...@@ -9,7 +9,7 @@ describe 'Graphql Field feature flags' do
let(:feature_flag) { 'test_feature' } let(:feature_flag) { 'test_feature' }
let(:test_object) { double(name: 'My name') } let(:test_object) { double(name: 'My name') }
let(:query_string) { '{ item() { name } }' } let(:query_string) { '{ item { name } }' }
let(:result) { execute_query(query_type)['data'] } let(:result) { execute_query(query_type)['data'] }
subject { result } subject { result }
......
...@@ -27,11 +27,11 @@ describe GitlabSchema do ...@@ -27,11 +27,11 @@ describe GitlabSchema do
end end
it 'has the base mutation' do it 'has the base mutation' do
expect(described_class.mutation).to eq(::Types::MutationType.to_graphql) expect(described_class.mutation).to eq(::Types::MutationType)
end end
it 'has the base query' do it 'has the base query' do
expect(described_class.query).to eq(::Types::QueryType.to_graphql) expect(described_class.query).to eq(::Types::QueryType)
end end
it 'paginates active record relations using `Connections::Keyset::Connection`' do it 'paginates active record relations using `Connections::Keyset::Connection`' do
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe GitlabSchema.types['AwardEmoji'] do describe GitlabSchema.types['AwardEmoji'] do
it { expect(described_class.graphql_name).to eq('AwardEmoji') } it { expect(described_class.graphql_name).to eq('AwardEmoji') }
it { is_expected.to require_graphql_authorizations(:read_emoji) } it { expect(described_class).to require_graphql_authorizations(:read_emoji) }
it { expect(described_class).to have_graphql_fields(:description, :unicode_version, :emoji, :name, :unicode, :user) } it { expect(described_class).to have_graphql_fields(:description, :unicode_version, :emoji, :name, :unicode, :user) }
end end
...@@ -10,6 +10,6 @@ describe GitlabSchema.types['Board'] do ...@@ -10,6 +10,6 @@ describe GitlabSchema.types['Board'] do
it 'has specific fields' do it 'has specific fields' do
expected_fields = %w[id name] expected_fields = %w[id name]
is_expected.to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
end end
end end
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
describe GitlabSchema.types['DiffRefs'] do describe GitlabSchema.types['DiffRefs'] do
it { expect(described_class.graphql_name).to eq('DiffRefs') } it { expect(described_class.graphql_name).to eq('DiffRefs') }
it { is_expected.to have_graphql_fields(:head_sha, :base_sha, :start_sha).only } it { expect(described_class).to have_graphql_fields(:head_sha, :base_sha, :start_sha).only }
it { expect(described_class.fields['headSha'].type).to be_non_null } it { expect(described_class.fields['headSha'].type).to be_non_null }
it { expect(described_class.fields['baseSha'].type).not_to be_non_null } it { expect(described_class.fields['baseSha'].type).not_to be_non_null }
......
...@@ -10,8 +10,8 @@ describe GitlabSchema.types['Environment'] do ...@@ -10,8 +10,8 @@ describe GitlabSchema.types['Environment'] do
name id name id
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
it { is_expected.to require_graphql_authorizations(:read_environment) } it { expect(described_class).to require_graphql_authorizations(:read_environment) }
end end
...@@ -37,6 +37,6 @@ describe GitlabSchema.types['SentryDetailedError'] do ...@@ -37,6 +37,6 @@ describe GitlabSchema.types['SentryDetailedError'] do
tags tags
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -15,7 +15,7 @@ describe GitlabSchema.types['SentryErrorCollection'] do ...@@ -15,7 +15,7 @@ describe GitlabSchema.types['SentryErrorCollection'] do
error_stack_trace error_stack_trace
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
describe 'errors field' do describe 'errors field' do
......
...@@ -14,6 +14,6 @@ describe GitlabSchema.types['SentryErrorStackTraceEntry'] do ...@@ -14,6 +14,6 @@ describe GitlabSchema.types['SentryErrorStackTraceEntry'] do
trace_context trace_context
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -14,6 +14,6 @@ describe GitlabSchema.types['SentryErrorStackTrace'] do ...@@ -14,6 +14,6 @@ describe GitlabSchema.types['SentryErrorStackTrace'] do
stack_trace_entries stack_trace_entries
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -26,6 +26,6 @@ describe GitlabSchema.types['SentryError'] do ...@@ -26,6 +26,6 @@ describe GitlabSchema.types['SentryError'] do
frequency frequency
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -18,5 +18,5 @@ describe GitlabSchema.types['GrafanaIntegration'] do ...@@ -18,5 +18,5 @@ describe GitlabSchema.types['GrafanaIntegration'] do
it { expect(described_class).to require_graphql_authorizations(:admin_operations) } it { expect(described_class).to require_graphql_authorizations(:admin_operations) }
it { is_expected.to have_graphql_fields(*expected_fields) } it { expect(described_class).to have_graphql_fields(*expected_fields) }
end end
...@@ -19,7 +19,7 @@ describe GitlabSchema.types['Group'] do ...@@ -19,7 +19,7 @@ describe GitlabSchema.types['Group'] do
mentions_disabled parent boards mentions_disabled parent boards
] ]
is_expected.to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
end end
describe 'boards field' do describe 'boards field' do
......
...@@ -9,7 +9,7 @@ describe GitlabSchema.types['Issue'] do ...@@ -9,7 +9,7 @@ describe GitlabSchema.types['Issue'] do
it { expect(described_class).to require_graphql_authorizations(:read_issue) } it { expect(described_class).to require_graphql_authorizations(:read_issue) }
it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) } it { expect(described_class.interfaces).to include(Types::Notes::NoteableType) }
it 'has specific fields' do it 'has specific fields' do
fields = %i[iid title description state reference author assignees participants labels milestone due_date fields = %i[iid title description state reference author assignees participants labels milestone due_date
......
...@@ -5,8 +5,8 @@ describe GitlabSchema.types['Label'] do ...@@ -5,8 +5,8 @@ describe GitlabSchema.types['Label'] do
it 'has the correct fields' do it 'has the correct fields' do
expected_fields = [:id, :description, :description_html, :title, :color, :text_color] expected_fields = [:id, :description, :description_html, :title, :color, :text_color]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
it { is_expected.to require_graphql_authorizations(:read_label) } it { expect(described_class).to require_graphql_authorizations(:read_label) }
end end
...@@ -7,7 +7,7 @@ describe GitlabSchema.types['MergeRequest'] do ...@@ -7,7 +7,7 @@ describe GitlabSchema.types['MergeRequest'] do
it { expect(described_class).to require_graphql_authorizations(:read_merge_request) } it { expect(described_class).to require_graphql_authorizations(:read_merge_request) }
it { expect(described_class.interfaces).to include(Types::Notes::NoteableType.to_graphql) } it { expect(described_class.interfaces).to include(Types::Notes::NoteableType) }
it 'has the expected fields' do it 'has the expected fields' do
expected_fields = %w[ expected_fields = %w[
...@@ -25,6 +25,6 @@ describe GitlabSchema.types['MergeRequest'] do ...@@ -25,6 +25,6 @@ describe GitlabSchema.types['MergeRequest'] do
total_time_spent reference total_time_spent reference
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -4,5 +4,5 @@ require 'spec_helper' ...@@ -4,5 +4,5 @@ require 'spec_helper'
describe GitlabSchema.types['Metadata'] do describe GitlabSchema.types['Metadata'] do
it { expect(described_class.graphql_name).to eq('Metadata') } it { expect(described_class.graphql_name).to eq('Metadata') }
it { is_expected.to require_graphql_authorizations(:read_instance_metadata) } it { expect(described_class).to require_graphql_authorizations(:read_instance_metadata) }
end end
...@@ -11,8 +11,8 @@ describe GitlabSchema.types['Namespace'] do ...@@ -11,8 +11,8 @@ describe GitlabSchema.types['Namespace'] do
lfs_enabled request_access_enabled projects root_storage_statistics lfs_enabled request_access_enabled projects root_storage_statistics
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
it { is_expected.to require_graphql_authorizations(:read_namespace) } it { expect(described_class).to require_graphql_authorizations(:read_namespace) }
end end
...@@ -7,6 +7,6 @@ describe GitlabSchema.types['DiffPosition'] do ...@@ -7,6 +7,6 @@ describe GitlabSchema.types['DiffPosition'] do
:new_path, :position_type, :old_line, :new_line, :x, :y, :new_path, :position_type, :old_line, :new_line, :x, :y,
:width, :height] :width, :height]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe GitlabSchema.types['Discussion'] do describe GitlabSchema.types['Discussion'] do
it { is_expected.to have_graphql_fields(:id, :created_at, :notes, :reply_id) } it { expect(described_class).to have_graphql_fields(:id, :created_at, :notes, :reply_id) }
it { is_expected.to require_graphql_authorizations(:read_note) } it { expect(described_class).to require_graphql_authorizations(:read_note) }
end end
...@@ -7,9 +7,9 @@ describe GitlabSchema.types['Note'] do ...@@ -7,9 +7,9 @@ describe GitlabSchema.types['Note'] do
:updated_at, :discussion, :resolvable, :position, :user_permissions, :updated_at, :discussion, :resolvable, :position, :user_permissions,
:resolved_by, :resolved_at, :system, :body_html] :resolved_by, :resolved_at, :system, :body_html]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
it { is_expected.to expose_permissions_using(Types::PermissionTypes::Note) } it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Note) }
it { is_expected.to require_graphql_authorizations(:read_note) } it { expect(described_class).to require_graphql_authorizations(:read_note) }
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Types::Notes::NoteableType do describe Types::Notes::NoteableType do
it { is_expected.to have_graphql_fields(:notes, :discussions) } it { expect(described_class).to have_graphql_fields(:notes, :discussions) }
describe ".resolve_type" do describe ".resolve_type" do
it 'knows the correct type for objects' do it 'knows the correct type for objects' do
......
...@@ -19,13 +19,13 @@ describe Types::PermissionTypes::BasePermissionType do ...@@ -19,13 +19,13 @@ describe Types::PermissionTypes::BasePermissionType do
describe '.permission_field' do describe '.permission_field' do
it 'adds a field for the required permission' do it 'adds a field for the required permission' do
is_expected.to have_graphql_field(:do_stuff) expect(test_type).to have_graphql_field(:do_stuff)
end end
end end
describe '.ability_field' do describe '.ability_field' do
it 'adds a field for the required permission' do it 'adds a field for the required permission' do
is_expected.to have_graphql_field(:read_issue) expect(test_type).to have_graphql_field(:read_issue)
end end
it 'does not add a resolver block if another resolving param is passed' do it 'does not add a resolver block if another resolving param is passed' do
...@@ -44,7 +44,7 @@ describe Types::PermissionTypes::BasePermissionType do ...@@ -44,7 +44,7 @@ describe Types::PermissionTypes::BasePermissionType do
describe '.abilities' do describe '.abilities' do
it 'adds a field for the passed permissions' do it 'adds a field for the passed permissions' do
is_expected.to have_graphql_field(:admin_issue) expect(test_type).to have_graphql_field(:admin_issue)
end end
end end
end end
...@@ -8,6 +8,6 @@ describe GitlabSchema.types['NotePermissions'] do ...@@ -8,6 +8,6 @@ describe GitlabSchema.types['NotePermissions'] do
:read_note, :create_note, :admin_note, :resolve_note, :award_emoji :read_note, :create_note, :admin_note, :resolve_note, :award_emoji
] ]
is_expected.to have_graphql_fields(expected_permissions) expect(described_class).to have_graphql_fields(expected_permissions)
end end
end end
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
describe GitlabSchema.types['ProjectStatistics'] do describe GitlabSchema.types['ProjectStatistics'] do
it "has all the required fields" do it "has all the required fields" do
is_expected.to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size,
:build_artifacts_size, :packages_size, :commit_count, :build_artifacts_size, :packages_size, :commit_count,
:wiki_size) :wiki_size)
end end
......
...@@ -27,7 +27,7 @@ describe GitlabSchema.types['Project'] do ...@@ -27,7 +27,7 @@ describe GitlabSchema.types['Project'] do
boards boards
] ]
is_expected.to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
end end
describe 'issue field' do describe 'issue field' do
......
...@@ -7,7 +7,7 @@ describe GitlabSchema.types['Repository'] do ...@@ -7,7 +7,7 @@ describe GitlabSchema.types['Repository'] do
it { expect(described_class).to require_graphql_authorizations(:download_code) } it { expect(described_class).to require_graphql_authorizations(:download_code) }
it { is_expected.to have_graphql_field(:root_ref) } it { expect(described_class).to have_graphql_field(:root_ref) }
it { is_expected.to have_graphql_field(:tree) } it { expect(described_class).to have_graphql_field(:tree) }
end end
...@@ -6,9 +6,9 @@ describe GitlabSchema.types['RootStorageStatistics'] do ...@@ -6,9 +6,9 @@ describe GitlabSchema.types['RootStorageStatistics'] do
it { expect(described_class.graphql_name).to eq('RootStorageStatistics') } it { expect(described_class.graphql_name).to eq('RootStorageStatistics') }
it 'has all the required fields' do it 'has all the required fields' do
is_expected.to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size,
:build_artifacts_size, :packages_size, :wiki_size) :build_artifacts_size, :packages_size, :wiki_size)
end end
it { is_expected.to require_graphql_authorizations(:read_statistics) } it { expect(described_class).to require_graphql_authorizations(:read_statistics) }
end end
...@@ -10,7 +10,7 @@ describe GitlabSchema.types['Snippet'] do ...@@ -10,7 +10,7 @@ describe GitlabSchema.types['Snippet'] do
:web_url, :raw_url, :notes, :discussions, :web_url, :raw_url, :notes, :discussions,
:user_permissions, :description_html, :blob] :user_permissions, :description_html, :blob]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
describe 'authorizations' do describe 'authorizations' do
......
...@@ -8,6 +8,6 @@ describe GitlabSchema.types['SnippetBlob'] do ...@@ -8,6 +8,6 @@ describe GitlabSchema.types['SnippetBlob'] do
:raw_path, :size, :binary, :name, :path, :raw_path, :size, :binary, :name, :path,
:simple_viewer, :rich_viewer, :mode] :simple_viewer, :rich_viewer, :mode]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -7,6 +7,6 @@ describe GitlabSchema.types['SnippetBlobViewer'] do ...@@ -7,6 +7,6 @@ describe GitlabSchema.types['SnippetBlobViewer'] do
expected_fields = [:type, :load_async, :too_large, :collapsed, expected_fields = [:type, :load_async, :too_large, :collapsed,
:render_error, :file_type, :loading_partial_name] :render_error, :file_type, :loading_partial_name]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
end end
...@@ -6,7 +6,7 @@ describe GitlabSchema.types['Todo'] do ...@@ -6,7 +6,7 @@ describe GitlabSchema.types['Todo'] do
it 'has the correct fields' do it 'has the correct fields' do
expected_fields = [:id, :project, :group, :author, :action, :target_type, :body, :state, :created_at] expected_fields = [:id, :project, :group, :author, :action, :target_type, :body, :state, :created_at]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
it { expect(described_class).to require_graphql_authorizations(:read_todo) } it { expect(described_class).to require_graphql_authorizations(:read_todo) }
......
...@@ -12,7 +12,7 @@ describe GitlabSchema.types['User'] do ...@@ -12,7 +12,7 @@ describe GitlabSchema.types['User'] do
user_permissions snippets name username avatarUrl webUrl todos user_permissions snippets name username avatarUrl webUrl todos
] ]
is_expected.to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
end end
describe 'snippets field' do describe 'snippets field' do
......
...@@ -71,10 +71,10 @@ module GraphqlHelpers ...@@ -71,10 +71,10 @@ module GraphqlHelpers
mutation_name = GraphqlHelpers.fieldnamerize(name) mutation_name = GraphqlHelpers.fieldnamerize(name)
input_variable_name = "$#{input_variable_name_for_mutation(name)}" input_variable_name = "$#{input_variable_name_for_mutation(name)}"
mutation_field = GitlabSchema.mutation.fields[mutation_name] mutation_field = GitlabSchema.mutation.fields[mutation_name]
fields ||= all_graphql_fields_for(mutation_field.type) fields ||= all_graphql_fields_for(mutation_field.type.to_graphql)
query = <<~MUTATION query = <<~MUTATION
mutation(#{input_variable_name}: #{mutation_field.arguments['input'].type}) { mutation(#{input_variable_name}: #{mutation_field.arguments['input'].type.to_graphql}) {
#{mutation_name}(input: #{input_variable_name}) { #{mutation_name}(input: #{input_variable_name}) {
#{fields} #{fields}
} }
...@@ -118,15 +118,22 @@ module GraphqlHelpers ...@@ -118,15 +118,22 @@ module GraphqlHelpers
GraphqlHelpers.fieldnamerize(input_type) GraphqlHelpers.fieldnamerize(input_type)
end end
def query_graphql_field(name, attributes = {}, fields = nil) def field_with_params(name, attributes = {})
field_params = if attributes.present? namerized = GraphqlHelpers.fieldnamerize(name.to_s)
return "#{namerized}" if attributes.blank?
field_params = if attributes.is_a?(Hash)
"(#{attributes_to_graphql(attributes)})" "(#{attributes_to_graphql(attributes)})"
else else
'' "(#{attributes})"
end end
"#{namerized}#{field_params}"
end
def query_graphql_field(name, attributes = {}, fields = nil)
<<~QUERY <<~QUERY
#{GraphqlHelpers.fieldnamerize(name.to_s)}#{field_params} #{field_with_params(name, attributes)}
#{wrap_fields(fields || all_graphql_fields_for(name.to_s.classify))} #{wrap_fields(fields || all_graphql_fields_for(name.to_s.classify))}
QUERY QUERY
end end
...@@ -300,7 +307,7 @@ module GraphqlHelpers ...@@ -300,7 +307,7 @@ module GraphqlHelpers
end end
def field_type(field) def field_type(field)
field_type = field.type field_type = field.type.respond_to?(:to_graphql) ? field.type.to_graphql : field.type
# The type could be nested. For example `[GraphQL::STRING_TYPE]`: # The type could be nested. For example `[GraphQL::STRING_TYPE]`:
# - List # - List
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
RSpec::Matchers.define :require_graphql_authorizations do |*expected| RSpec::Matchers.define :require_graphql_authorizations do |*expected|
match do |field| match do |field|
expect(field.metadata[:authorize]).to eq(*expected) expect(field.to_graphql.metadata[:authorize]).to eq(*expected)
end end
end end
...@@ -87,13 +87,13 @@ end ...@@ -87,13 +87,13 @@ end
RSpec::Matchers.define :have_graphql_type do |expected| RSpec::Matchers.define :have_graphql_type do |expected|
match do |field| match do |field|
expect(field.type).to eq(expected.to_graphql) expect(field.type).to eq(expected)
end end
end end
RSpec::Matchers.define :have_non_null_graphql_type do |expected| RSpec::Matchers.define :have_non_null_graphql_type do |expected|
match do |field| match do |field|
expect(field.type).to eq(!expected.to_graphql) expect(field.type.to_graphql).to eq(!expected.to_graphql)
end end
end end
...@@ -101,16 +101,16 @@ RSpec::Matchers.define :have_graphql_resolver do |expected| ...@@ -101,16 +101,16 @@ RSpec::Matchers.define :have_graphql_resolver do |expected|
match do |field| match do |field|
case expected case expected
when Method when Method
expect(field.metadata[:type_class].resolve_proc).to eq(expected) expect(field.to_graphql.metadata[:type_class].resolve_proc).to eq(expected)
else else
expect(field.metadata[:type_class].resolver).to eq(expected) expect(field.to_graphql.metadata[:type_class].resolver).to eq(expected)
end end
end end
end end
RSpec::Matchers.define :have_graphql_extension do |expected| RSpec::Matchers.define :have_graphql_extension do |expected|
match do |field| match do |field|
expect(field.metadata[:type_class].extensions).to include(expected) expect(field.to_graphql.metadata[:type_class].extensions).to include(expected)
end end
end end
......
...@@ -15,7 +15,7 @@ RSpec.shared_context 'group and project boards query context' do ...@@ -15,7 +15,7 @@ RSpec.shared_context 'group and project boards query context' do
board_parent_type, board_parent_type,
{ 'fullPath' => board_parent.full_path }, { 'fullPath' => board_parent.full_path },
<<~BOARDS <<~BOARDS
boards(#{board_params}) { #{field_with_params('boards', board_params)} {
pageInfo { pageInfo {
startCursor startCursor
endCursor endCursor
...@@ -35,7 +35,7 @@ RSpec.shared_context 'group and project boards query context' do ...@@ -35,7 +35,7 @@ RSpec.shared_context 'group and project boards query context' do
board_parent_type, board_parent_type,
{ 'fullPath' => board_parent.full_path }, { 'fullPath' => board_parent.full_path },
<<~BOARD <<~BOARD
board(#{board_params}) { #{field_with_params('board', board_params)} {
#{all_graphql_fields_for('board'.classify)} #{all_graphql_fields_for('board'.classify)}
} }
BOARD BOARD
......
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