From 846ef5c23b608c64f58c7ef348059209e0051535 Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Thu, 27 Feb 2020 10:27:30 -0600 Subject: [PATCH] Upgrade to graphql gem to 1.10.5 - Fix how we call include_graphql_fields from described_class.new to described_class - Fix require_graphql_authorizations matcher - Update have_graphql_type and have_graphql_resolver - Fix how we call require_graphql_authorizations from described_class.new to described_class - Fix how we call have_graphql_fields from described_class.new to described_class - Fix how we call have_graphql_field from described_class.new to described_class - Add `field_with_params` graphql helper - Fix how `field_type` determines type - Use `resolve_field` instead of `resolve` so that `extras` metadata is properly processed - Fix returned error message check --- Gemfile | 2 +- Gemfile.lock | 4 ++-- .../design_at_version_type_spec.rb | 4 +--- .../types/design_management_type_spec.rb | 2 +- ee/spec/graphql/types/epic_type_spec.rb | 4 ++-- ee/spec/graphql/types/project_type_spec.rb | 2 +- ee/spec/graphql/types/query_type_spec.rb | 2 +- .../mutations/epic_tree/reorder_spec.rb | 2 +- .../mutations/issues/set_weight_spec.rb | 2 +- .../graphql/design_fields_shared_examples.rb | 12 +++++------ spec/graphql/features/authorization_spec.rb | 4 ++-- spec/graphql/features/feature_flag_spec.rb | 2 +- spec/graphql/gitlab_schema_spec.rb | 4 ++-- .../award_emojis/award_emoji_type_spec.rb | 2 +- spec/graphql/types/board_type_spec.rb | 2 +- spec/graphql/types/diff_refs_type_spec.rb | 2 +- spec/graphql/types/environment_type_spec.rb | 4 ++-- .../sentry_detailed_error_type_spec.rb | 2 +- .../sentry_error_collection_type_spec.rb | 2 +- ...entry_error_stack_trace_entry_type_spec.rb | 2 +- .../sentry_error_stack_trace_type_spec.rb | 2 +- .../error_tracking/sentry_error_type_spec.rb | 2 +- .../types/grafana_integration_type_spec.rb | 2 +- spec/graphql/types/group_type_spec.rb | 2 +- spec/graphql/types/issue_type_spec.rb | 2 +- spec/graphql/types/label_type_spec.rb | 4 ++-- spec/graphql/types/merge_request_type_spec.rb | 4 ++-- spec/graphql/types/metadata_type_spec.rb | 2 +- spec/graphql/types/namespace_type_spec.rb | 4 ++-- .../types/notes/diff_position_type_spec.rb | 2 +- .../types/notes/discussion_type_spec.rb | 4 ++-- spec/graphql/types/notes/note_type_spec.rb | 6 +++--- .../graphql/types/notes/noteable_type_spec.rb | 2 +- .../base_permission_type_spec.rb | 6 +++--- .../types/permission_types/note_spec.rb | 2 +- .../types/project_statistics_type_spec.rb | 2 +- spec/graphql/types/project_type_spec.rb | 2 +- spec/graphql/types/repository_type_spec.rb | 4 ++-- .../root_storage_statistics_type_spec.rb | 4 ++-- spec/graphql/types/snippet_type_spec.rb | 2 +- spec/graphql/types/snippets/blob_type_spec.rb | 2 +- .../types/snippets/blob_viewer_type_spec.rb | 2 +- spec/graphql/types/todo_type_spec.rb | 2 +- spec/graphql/types/user_type_spec.rb | 2 +- spec/support/helpers/graphql_helpers.rb | 21 ++++++++++++------- spec/support/matchers/graphql_matchers.rb | 12 +++++------ ...and_project_boards_query_shared_context.rb | 4 ++-- 47 files changed, 86 insertions(+), 81 deletions(-) diff --git a/Gemfile b/Gemfile index 8c8802e4435873..b2734269a8c0ab 100644 --- a/Gemfile +++ b/Gemfile @@ -87,7 +87,7 @@ gem 'grape-entity', '~> 0.7.1' gem 'rack-cors', '~> 1.0.6', require: 'rack/cors' # 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 # 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 diff --git a/Gemfile.lock b/Gemfile.lock index 3bbe3020b70c2e..e96a38ccf22ff0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -456,7 +456,7 @@ GEM graphiql-rails (1.4.10) railties sprockets-rails - graphql (1.9.19) + graphql (1.10.5) graphql-docs (1.6.0) commonmarker (~> 0.16) escape_utils (~> 1.2) @@ -1252,7 +1252,7 @@ DEPENDENCIES grape-path-helpers (~> 1.2) grape_logging (~> 1.7) graphiql-rails (~> 1.4.10) - graphql (~> 1.9.19) + graphql (~> 1.10.5) graphql-docs (~> 1.6.0) grpc (~> 1.24.0) gssapi diff --git a/ee/spec/graphql/types/design_management/design_at_version_type_spec.rb b/ee/spec/graphql/types/design_management/design_at_version_type_spec.rb index 5865015beeccf5..1453d73d59c7fe 100644 --- a/ee/spec/graphql/types/design_management/design_at_version_type_spec.rb +++ b/ee/spec/graphql/types/design_management/design_at_version_type_spec.rb @@ -2,9 +2,7 @@ require 'spec_helper' -# describe GitlabSchema.types['DesignAtVersion'] do -# This not available on the schema until we mount it somewhere -describe ::Types::DesignManagement::DesignAtVersionType.to_graphql do +describe GitlabSchema.types['DesignAtVersion'] do it_behaves_like 'a GraphQL type with design fields' do let(:extra_design_fields) { %i[version design] } let_it_be(:design) { create(:design, :with_versions) } diff --git a/ee/spec/graphql/types/design_management_type_spec.rb b/ee/spec/graphql/types/design_management_type_spec.rb index 9cff40f425ef67..a6204f20f23a1b 100644 --- a/ee/spec/graphql/types/design_management_type_spec.rb +++ b/ee/spec/graphql/types/design_management_type_spec.rb @@ -3,5 +3,5 @@ require 'spec_helper' 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 diff --git a/ee/spec/graphql/types/epic_type_spec.rb b/ee/spec/graphql/types/epic_type_spec.rb index e90230b732a869..8af54dcd17bfcf 100644 --- a/ee/spec/graphql/types/epic_type_spec.rb +++ b/ee/spec/graphql/types/epic_type_spec.rb @@ -23,7 +23,7 @@ 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 diff --git a/ee/spec/graphql/types/project_type_spec.rb b/ee/spec/graphql/types/project_type_spec.rb index c307574d3a6917..fd85d026be26c1 100644 --- a/ee/spec/graphql/types/project_type_spec.rb +++ b/ee/spec/graphql/types/project_type_spec.rb @@ -6,7 +6,7 @@ it 'includes the ee specific fields' do 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 describe 'vulnerabilities' do diff --git a/ee/spec/graphql/types/query_type_spec.rb b/ee/spec/graphql/types/query_type_spec.rb index f85e44c7b6e45f..32b56a61f0bbfa 100644 --- a/ee/spec/graphql/types/query_type_spec.rb +++ b/ee/spec/graphql/types/query_type_spec.rb @@ -4,6 +4,6 @@ describe GitlabSchema.types['Query'] 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 diff --git a/ee/spec/requests/api/graphql/mutations/epic_tree/reorder_spec.rb b/ee/spec/requests/api/graphql/mutations/epic_tree/reorder_spec.rb index 0472ece5c28fd4..a7a7b267990e5b 100644 --- a/ee/spec/requests/api/graphql/mutations/epic_tree/reorder_spec.rb +++ b/ee/spec/requests/api/graphql/mutations/epic_tree/reorder_spec.rb @@ -90,7 +90,7 @@ def mutation_response end 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 context 'when object being moved is not supported type' do diff --git a/ee/spec/requests/api/graphql/mutations/issues/set_weight_spec.rb b/ee/spec/requests/api/graphql/mutations/issues/set_weight_spec.rb index 1cf7ea2cce519b..b3ec1f39e2dfe6 100644 --- a/ee/spec/requests/api/graphql/mutations/issues/set_weight_spec.rb +++ b/ee/spec/requests/api/graphql/mutations/issues/set_weight_spec.rb @@ -55,7 +55,7 @@ def mutation_response let(:input) { { weight: "2" } } 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)" post_graphql_mutation(mutation, current_user: current_user) diff --git a/ee/spec/support/shared_examples/graphql/design_fields_shared_examples.rb b/ee/spec/support/shared_examples/graphql/design_fields_shared_examples.rb index f5e77b2c8961ee..029d7e677da910 100644 --- a/ee/spec/support/shared_examples/graphql/design_fields_shared_examples.rb +++ b/ee/spec/support/shared_examples/graphql/design_fields_shared_examples.rb @@ -22,7 +22,7 @@ notes_count ] + extra_design_fields - is_expected.to have_graphql_fields(*expected_fields).only + expect(described_class).to have_graphql_fields(*expected_fields).only end describe '#image' do @@ -41,7 +41,7 @@ end 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 url = ::Gitlab::Routing.url_helpers.project_design_management_designs_raw_image_url(design.project, design, sha) @@ -67,10 +67,10 @@ # = 10 expect(instance).not_to eq(instance_b) # preload designs themselves. expect do - image_a = field.resolve(instance, args, context) - image_b = field.resolve(instance, args, context) - image_c = field.resolve(instance_b, args, context) - image_d = field.resolve(instance_b, args, context) + image_a = field.resolve_field(instance, args, context) + image_b = field.resolve_field(instance, args, context) + image_c = field.resolve_field(instance_b, args, context) + image_d = field.resolve_field(instance_b, args, context) expect(image_a).to eq(image_b) expect(image_c).not_to eq(image_b) expect(image_c).to eq(image_d) diff --git a/spec/graphql/features/authorization_spec.rb b/spec/graphql/features/authorization_spec.rb index 44f47e6c7396e9..4f54695e5bef61 100644 --- a/spec/graphql/features/authorization_spec.rb +++ b/spec/graphql/features/authorization_spec.rb @@ -9,7 +9,7 @@ let(:permission_single) { :foo } let(:permission_collection) { [:foo, :bar] } let(:test_object) { double(name: 'My name') } - let(:query_string) { '{ item() { name } }' } + let(:query_string) { '{ item { name } }' } let(:result) { execute_query(query_type)['data'] } subject { result['item'] } @@ -177,7 +177,7 @@ end 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(:type) do diff --git a/spec/graphql/features/feature_flag_spec.rb b/spec/graphql/features/feature_flag_spec.rb index 13b1e472fab15a..51914cf0ca8f76 100644 --- a/spec/graphql/features/feature_flag_spec.rb +++ b/spec/graphql/features/feature_flag_spec.rb @@ -9,7 +9,7 @@ let(:feature_flag) { 'test_feature' } let(:test_object) { double(name: 'My name') } - let(:query_string) { '{ item() { name } }' } + let(:query_string) { '{ item { name } }' } let(:result) { execute_query(query_type)['data'] } subject { result } diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index d0eb0475879af7..bd22458355c3d4 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -27,11 +27,11 @@ end 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 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 it 'paginates active record relations using `Connections::Keyset::Connection`' do diff --git a/spec/graphql/types/award_emojis/award_emoji_type_spec.rb b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb index 5663a3d7195034..de5ece3b74956b 100644 --- a/spec/graphql/types/award_emojis/award_emoji_type_spec.rb +++ b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb @@ -5,7 +5,7 @@ describe GitlabSchema.types['AwardEmoji'] do 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) } end diff --git a/spec/graphql/types/board_type_spec.rb b/spec/graphql/types/board_type_spec.rb index 9d18065bbcde5f..1ca4bf18b57fd5 100644 --- a/spec/graphql/types/board_type_spec.rb +++ b/spec/graphql/types/board_type_spec.rb @@ -10,6 +10,6 @@ it 'has specific fields' do expected_fields = %w[id name] - is_expected.to include_graphql_fields(*expected_fields) + expect(described_class).to include_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/diff_refs_type_spec.rb b/spec/graphql/types/diff_refs_type_spec.rb index 85225e5809c4ef..a6ead27455f015 100644 --- a/spec/graphql/types/diff_refs_type_spec.rb +++ b/spec/graphql/types/diff_refs_type_spec.rb @@ -5,7 +5,7 @@ describe GitlabSchema.types['DiffRefs'] do 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['baseSha'].type).not_to be_non_null } diff --git a/spec/graphql/types/environment_type_spec.rb b/spec/graphql/types/environment_type_spec.rb index cf30893b3cada3..9e8f13e4c2e6ed 100644 --- a/spec/graphql/types/environment_type_spec.rb +++ b/spec/graphql/types/environment_type_spec.rb @@ -10,8 +10,8 @@ name id ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end - it { is_expected.to require_graphql_authorizations(:read_environment) } + it { expect(described_class).to require_graphql_authorizations(:read_environment) } end diff --git a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb index 3a512fee3b377d..44652f831b52f5 100644 --- a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb @@ -37,6 +37,6 @@ tags ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb index 3de0a359c15ff8..20ec31391d8297 100644 --- a/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb @@ -15,7 +15,7 @@ error_stack_trace ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end describe 'errors field' do diff --git a/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb index ce5fade6fcc92f..05cc2ca7612b35 100644 --- a/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb @@ -14,6 +14,6 @@ trace_context ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb index ac41e6903e5744..2a422228f72cd7 100644 --- a/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb @@ -14,6 +14,6 @@ stack_trace_entries ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/error_tracking/sentry_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_type_spec.rb index 51acd035024503..4676d91ef9c018 100644 --- a/spec/graphql/types/error_tracking/sentry_error_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_type_spec.rb @@ -26,6 +26,6 @@ frequency ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/grafana_integration_type_spec.rb b/spec/graphql/types/grafana_integration_type_spec.rb index ddfedc5a75c303..ac26911acbf962 100644 --- a/spec/graphql/types/grafana_integration_type_spec.rb +++ b/spec/graphql/types/grafana_integration_type_spec.rb @@ -18,5 +18,5 @@ 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 diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index 240dd9fa5e251b..532f1a4b53d8b6 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -19,7 +19,7 @@ mentions_disabled parent boards ] - is_expected.to include_graphql_fields(*expected_fields) + expect(described_class).to include_graphql_fields(*expected_fields) end describe 'boards field' do diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index daa2224ef204f0..ebe48c17c111bd 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -9,7 +9,7 @@ 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 fields = %i[iid title description state reference author assignees participants labels milestone due_date diff --git a/spec/graphql/types/label_type_spec.rb b/spec/graphql/types/label_type_spec.rb index a023a75eeffe4f..71b86d9b528fc1 100644 --- a/spec/graphql/types/label_type_spec.rb +++ b/spec/graphql/types/label_type_spec.rb @@ -5,8 +5,8 @@ it 'has the correct fields' do 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 - it { is_expected.to require_graphql_authorizations(:read_label) } + it { expect(described_class).to require_graphql_authorizations(:read_label) } end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 04e9bb6861f458..0c83ebd3de9b13 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -7,7 +7,7 @@ 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 expected_fields = %w[ @@ -25,6 +25,6 @@ total_time_spent reference ] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/metadata_type_spec.rb b/spec/graphql/types/metadata_type_spec.rb index 2988f3c6ba59fe..c8270a8c2f5ef1 100644 --- a/spec/graphql/types/metadata_type_spec.rb +++ b/spec/graphql/types/metadata_type_spec.rb @@ -4,5 +4,5 @@ describe GitlabSchema.types['Metadata'] do 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 diff --git a/spec/graphql/types/namespace_type_spec.rb b/spec/graphql/types/namespace_type_spec.rb index f476dd7286f130..6c2ba70cf4c6d1 100644 --- a/spec/graphql/types/namespace_type_spec.rb +++ b/spec/graphql/types/namespace_type_spec.rb @@ -11,8 +11,8 @@ 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 - it { is_expected.to require_graphql_authorizations(:read_namespace) } + it { expect(described_class).to require_graphql_authorizations(:read_namespace) } end diff --git a/spec/graphql/types/notes/diff_position_type_spec.rb b/spec/graphql/types/notes/diff_position_type_spec.rb index aa08daaacd4542..01f355cb2786e4 100644 --- a/spec/graphql/types/notes/diff_position_type_spec.rb +++ b/spec/graphql/types/notes/diff_position_type_spec.rb @@ -7,6 +7,6 @@ :new_path, :position_type, :old_line, :new_line, :x, :y, :width, :height] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/notes/discussion_type_spec.rb b/spec/graphql/types/notes/discussion_type_spec.rb index ba7fc961212e8f..804785ba67d5e3 100644 --- a/spec/graphql/types/notes/discussion_type_spec.rb +++ b/spec/graphql/types/notes/discussion_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' 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 diff --git a/spec/graphql/types/notes/note_type_spec.rb b/spec/graphql/types/notes/note_type_spec.rb index e8a58da4b1786e..809f54c120cd20 100644 --- a/spec/graphql/types/notes/note_type_spec.rb +++ b/spec/graphql/types/notes/note_type_spec.rb @@ -7,9 +7,9 @@ :updated_at, :discussion, :resolvable, :position, :user_permissions, :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 - it { is_expected.to expose_permissions_using(Types::PermissionTypes::Note) } - it { is_expected.to require_graphql_authorizations(:read_note) } + it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Note) } + it { expect(described_class).to require_graphql_authorizations(:read_note) } end diff --git a/spec/graphql/types/notes/noteable_type_spec.rb b/spec/graphql/types/notes/noteable_type_spec.rb index d10c79b5344fe4..a4259e160e09b4 100644 --- a/spec/graphql/types/notes/noteable_type_spec.rb +++ b/spec/graphql/types/notes/noteable_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' 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 it 'knows the correct type for objects' do diff --git a/spec/graphql/types/permission_types/base_permission_type_spec.rb b/spec/graphql/types/permission_types/base_permission_type_spec.rb index aa6b432000631e..4c6d5fd369ab45 100644 --- a/spec/graphql/types/permission_types/base_permission_type_spec.rb +++ b/spec/graphql/types/permission_types/base_permission_type_spec.rb @@ -19,13 +19,13 @@ describe '.permission_field' 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 describe '.ability_field' 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 it 'does not add a resolver block if another resolving param is passed' do @@ -44,7 +44,7 @@ describe '.abilities' 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 diff --git a/spec/graphql/types/permission_types/note_spec.rb b/spec/graphql/types/permission_types/note_spec.rb index a7811fc20e50d4..a2becb6892b55f 100644 --- a/spec/graphql/types/permission_types/note_spec.rb +++ b/spec/graphql/types/permission_types/note_spec.rb @@ -8,6 +8,6 @@ :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 diff --git a/spec/graphql/types/project_statistics_type_spec.rb b/spec/graphql/types/project_statistics_type_spec.rb index e9feac57a360da..fbea780494b055 100644 --- a/spec/graphql/types/project_statistics_type_spec.rb +++ b/spec/graphql/types/project_statistics_type_spec.rb @@ -4,7 +4,7 @@ describe GitlabSchema.types['ProjectStatistics'] 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, :wiki_size) end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 9c6d1e3f35c402..475ae9ff5f62ce 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -27,7 +27,7 @@ boards ] - is_expected.to include_graphql_fields(*expected_fields) + expect(described_class).to include_graphql_fields(*expected_fields) end describe 'issue field' do diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb index 236f9bb9459391..f746e75b5742c9 100644 --- a/spec/graphql/types/repository_type_spec.rb +++ b/spec/graphql/types/repository_type_spec.rb @@ -7,7 +7,7 @@ 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 diff --git a/spec/graphql/types/root_storage_statistics_type_spec.rb b/spec/graphql/types/root_storage_statistics_type_spec.rb index 8c69c13aa737d1..b796b974b8292e 100644 --- a/spec/graphql/types/root_storage_statistics_type_spec.rb +++ b/spec/graphql/types/root_storage_statistics_type_spec.rb @@ -6,9 +6,9 @@ it { expect(described_class.graphql_name).to eq('RootStorageStatistics') } 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) end - it { is_expected.to require_graphql_authorizations(:read_statistics) } + it { expect(described_class).to require_graphql_authorizations(:read_statistics) } end diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index 97573f8c46be00..afac480d06b1ea 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -10,7 +10,7 @@ :web_url, :raw_url, :notes, :discussions, :user_permissions, :description_html, :blob] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end describe 'authorizations' do diff --git a/spec/graphql/types/snippets/blob_type_spec.rb b/spec/graphql/types/snippets/blob_type_spec.rb index b6253e96d60c51..da36ab80f44ae9 100644 --- a/spec/graphql/types/snippets/blob_type_spec.rb +++ b/spec/graphql/types/snippets/blob_type_spec.rb @@ -8,6 +8,6 @@ :raw_path, :size, :binary, :name, :path, :simple_viewer, :rich_viewer, :mode] - is_expected.to have_graphql_fields(*expected_fields) + expect(described_class).to have_graphql_fields(*expected_fields) end end diff --git a/spec/graphql/types/snippets/blob_viewer_type_spec.rb b/spec/graphql/types/snippets/blob_viewer_type_spec.rb index f1f7608cb698d7..a51d09813ab6cb 100644 --- a/spec/graphql/types/snippets/blob_viewer_type_spec.rb +++ b/spec/graphql/types/snippets/blob_viewer_type_spec.rb @@ -7,6 +7,6 @@ expected_fields = [:type, :load_async, :too_large, :collapsed, :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 diff --git a/spec/graphql/types/todo_type_spec.rb b/spec/graphql/types/todo_type_spec.rb index a5ea5bcffb073a..59118259d0941e 100644 --- a/spec/graphql/types/todo_type_spec.rb +++ b/spec/graphql/types/todo_type_spec.rb @@ -6,7 +6,7 @@ it 'has the correct fields' do 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 it { expect(described_class).to require_graphql_authorizations(:read_todo) } diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index b9174b9a90be0e..8c76ce43e95338 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -12,7 +12,7 @@ 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 describe 'snippets field' do diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 370162b45f08ff..1bb942ff39b393 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -71,10 +71,10 @@ def graphql_mutation(name, input, fields = nil) mutation_name = GraphqlHelpers.fieldnamerize(name) input_variable_name = "$#{input_variable_name_for_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 - 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}) { #{fields} } @@ -118,15 +118,22 @@ def input_variable_name_for_mutation(mutation_name) GraphqlHelpers.fieldnamerize(input_type) end - def query_graphql_field(name, attributes = {}, fields = nil) - field_params = if attributes.present? + def field_with_params(name, attributes = {}) + namerized = GraphqlHelpers.fieldnamerize(name.to_s) + return "#{namerized}" if attributes.blank? + + field_params = if attributes.is_a?(Hash) "(#{attributes_to_graphql(attributes)})" else - '' + "(#{attributes})" end + "#{namerized}#{field_params}" + end + + def query_graphql_field(name, attributes = {}, fields = nil) <<~QUERY - #{GraphqlHelpers.fieldnamerize(name.to_s)}#{field_params} + #{field_with_params(name, attributes)} #{wrap_fields(fields || all_graphql_fields_for(name.to_s.classify))} QUERY end @@ -300,7 +307,7 @@ def io_value?(value) end 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]`: # - List diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb index 31b0290bb15f1a..6439b68764e08a 100644 --- a/spec/support/matchers/graphql_matchers.rb +++ b/spec/support/matchers/graphql_matchers.rb @@ -2,7 +2,7 @@ RSpec::Matchers.define :require_graphql_authorizations do |*expected| match do |field| - expect(field.metadata[:authorize]).to eq(*expected) + expect(field.to_graphql.metadata[:authorize]).to eq(*expected) end end @@ -87,13 +87,13 @@ def expected_field_names RSpec::Matchers.define :have_graphql_type do |expected| match do |field| - expect(field.type).to eq(expected.to_graphql) + expect(field.type).to eq(expected) end end RSpec::Matchers.define :have_non_null_graphql_type do |expected| match do |field| - expect(field.type).to eq(!expected.to_graphql) + expect(field.type.to_graphql).to eq(!expected.to_graphql) end end @@ -101,16 +101,16 @@ def expected_field_names match do |field| case expected 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 - expect(field.metadata[:type_class].resolver).to eq(expected) + expect(field.to_graphql.metadata[:type_class].resolver).to eq(expected) end end end RSpec::Matchers.define :have_graphql_extension do |expected| 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 diff --git a/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb b/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb index ca77c68c130e5e..4c80bbef153695 100644 --- a/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb +++ b/spec/support/shared_contexts/requests/api/graphql/group_and_project_boards_query_shared_context.rb @@ -15,7 +15,7 @@ def query(board_params = params) board_parent_type, { 'fullPath' => board_parent.full_path }, <<~BOARDS - boards(#{board_params}) { + #{field_with_params('boards', board_params)} { pageInfo { startCursor endCursor @@ -35,7 +35,7 @@ def query_single_board(board_params = params) board_parent_type, { 'fullPath' => board_parent.full_path }, <<~BOARD - board(#{board_params}) { + #{field_with_params('board', board_params)} { #{all_graphql_fields_for('board'.classify)} } BOARD -- GitLab