Commit 43651bd7 authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch 'bw-graphql-remove-to_graphql' into 'master'

Remove calls to deprecated `to_graphql`

See merge request gitlab-org/gitlab!82739
parents 2121aba9 33d33c5a
......@@ -15,8 +15,11 @@ FactoryBot.define do
startsAt: Time.now,
cadence: { unit: %w(day month year week).sample, duration: 1 }
}
::Types::Dast::ProfileScheduleInputType.to_graphql
initialize_with { ::Types::Dast::ProfileScheduleInputType.new(arguments, defaults_used: [], context: context) }
initialize_with do
ruby_kwargs = arguments.transform_keys { |key| key.to_s.underscore.to_sym }
::Types::Dast::ProfileScheduleInputType.new(ruby_kwargs: ruby_kwargs, defaults_used: [], context: context)
end
end
end
......@@ -123,6 +123,7 @@ RSpec.describe Mutations::Dast::Profiles::Update do
context 'when associated dast profile schedule is not present' do
context 'when dast_profile_schedule param is present' do
let(:new_dast_profile_schedule) { create(:dast_profile_schedule_input_type) }
let(:new_dast_profile_schedule_h) { new_dast_profile_schedule.to_h }
subject do
mutation.resolve(**params.merge(dast_profile_schedule: new_dast_profile_schedule))
......@@ -134,10 +135,10 @@ RSpec.describe Mutations::Dast::Profiles::Update do
new_schedule = dast_profile.reload.dast_profile_schedule
aggregate_failures do
expect(new_schedule.timezone).to eq(new_dast_profile_schedule[:timezone])
expect(new_schedule.starts_at.to_i).to eq(new_dast_profile_schedule[:starts_at].to_i)
expect(new_schedule.cadence[:duration]).to eq(new_dast_profile_schedule[:cadence].duration)
expect(new_schedule.cadence[:unit]).to eq(new_dast_profile_schedule[:cadence].unit)
expect(new_schedule.timezone).to eq(new_dast_profile_schedule_h[:timezone])
expect(new_schedule.starts_at.to_i).to eq(new_dast_profile_schedule_h[:starts_at].to_i)
expect(new_schedule.cadence[:duration]).to eq(new_dast_profile_schedule_h[:cadence][:duration])
expect(new_schedule.cadence[:unit]).to eq(new_dast_profile_schedule_h[:cadence][:unit])
end
end
end
......
......@@ -42,7 +42,7 @@ RSpec.describe Resolvers::EpicsResolver do
it 'does not inflate the complexity' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: described_class, null: false, max_page_size: 100)
expect(field.to_graphql.complexity.call({}, { iid: [epic1.iid] }, 5)).to eq 6
expect(field.complexity.call({}, { iid: [epic1.iid] }, 5)).to eq 6
end
end
......@@ -59,8 +59,8 @@ RSpec.describe Resolvers::EpicsResolver do
it 'increases the complexity based on child_complexity and number of iids' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: described_class, null: false, max_page_size: 100)
expect(field.to_graphql.complexity.call({}, { iids: [epic1.iid] }, 5)).to eq 6
expect(field.to_graphql.complexity.call({}, { iids: [epic1.iid, epic2.iid] }, 5)).to eq 11
expect(field.complexity.call({}, { iids: [epic1.iid] }, 5)).to eq 6
expect(field.complexity.call({}, { iids: [epic1.iid, epic2.iid] }, 5)).to eq 11
end
end
......
......@@ -239,16 +239,16 @@ RSpec.describe Resolvers::BaseResolver do
it 'increases complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 1)
expect(field.to_graphql.complexity.call({}, { sort: 'foo' }, 1)).to eq 3
expect(field.to_graphql.complexity.call({}, { search: 'foo' }, 1)).to eq 7
expect(field.complexity.call({}, { sort: 'foo' }, 1)).to eq 3
expect(field.complexity.call({}, { search: 'foo' }, 1)).to eq 7
end
it 'does not increase complexity when filtering by iids' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 100)
expect(field.to_graphql.complexity.call({}, { sort: 'foo' }, 1)).to eq 6
expect(field.to_graphql.complexity.call({}, { sort: 'foo', iid: 1 }, 1)).to eq 3
expect(field.to_graphql.complexity.call({}, { sort: 'foo', iids: [1, 2, 3] }, 1)).to eq 3
expect(field.complexity.call({}, { sort: 'foo' }, 1)).to eq 6
expect(field.complexity.call({}, { sort: 'foo', iid: 1 }, 1)).to eq 3
expect(field.complexity.call({}, { sort: 'foo', iids: [1, 2, 3] }, 1)).to eq 3
end
end
......
......@@ -106,9 +106,9 @@ RSpec.describe ResolvesPipelines do
it 'increases field complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: resolver, null: false, max_page_size: 1)
expect(field.to_graphql.complexity.call({}, {}, 1)).to eq 2
expect(field.to_graphql.complexity.call({}, { sha: 'foo' }, 1)).to eq 4
expect(field.to_graphql.complexity.call({}, { sha: 'ref' }, 1)).to eq 4
expect(field.complexity.call({}, {}, 1)).to eq 2
expect(field.complexity.call({}, { sha: 'foo' }, 1)).to eq 4
expect(field.complexity.call({}, { sha: 'ref' }, 1)).to eq 4
end
def resolve_pipelines(args = {}, context = { current_user: current_user })
......
......@@ -618,8 +618,8 @@ RSpec.describe Resolvers::IssuesResolver do
it 'increases field complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 100)
expect(field.to_graphql.complexity.call({}, {}, 1)).to eq 4
expect(field.to_graphql.complexity.call({}, { labelName: 'foo' }, 1)).to eq 8
expect(field.complexity.call({}, {}, 1)).to eq 4
expect(field.complexity.call({}, { labelName: 'foo' }, 1)).to eq 8
end
def create_issue_with_severity(project, severity:)
......
......@@ -147,8 +147,8 @@ RSpec.describe Resolvers::NamespaceProjectsResolver do
it 'has an high complexity regardless of arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: described_class, null: false, max_page_size: 100)
expect(field.to_graphql.complexity.call({}, {}, 1)).to eq 24
expect(field.to_graphql.complexity.call({}, { include_subgroups: true }, 1)).to eq 24
expect(field.complexity.call({}, {}, 1)).to eq 24
expect(field.complexity.call({}, { include_subgroups: true }, 1)).to eq 24
end
def resolve_projects(args = { include_subgroups: false, sort: nil, search: nil, ids: nil }, context = { current_user: current_user })
......
......@@ -36,8 +36,8 @@ RSpec.describe Resolvers::ProjectResolver do
field1 = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: described_class, null: false, max_page_size: 100)
field2 = Types::BaseField.new(name: 'test', type: GraphQL::Types::String, resolver_class: described_class, null: false, max_page_size: 1)
expect(field1.to_graphql.complexity.call({}, {}, 1)).to eq 2
expect(field2.to_graphql.complexity.call({}, {}, 1)).to eq 2
expect(field1.complexity.call({}, {}, 1)).to eq 2
expect(field2.complexity.call({}, {}, 1)).to eq 2
end
def resolve_project(full_path)
......
......@@ -136,7 +136,7 @@ RSpec.describe Types::BaseEnum do
value 'TEST_VALUE', **args
end
enum.to_graphql.values['TEST_VALUE']
enum.values['TEST_VALUE']
end
end
end
......@@ -19,7 +19,7 @@ RSpec.describe Types::BaseField do
it 'defaults to 1' do
field = described_class.new(name: 'test', type: GraphQL::Types::String, null: true)
expect(field.to_graphql.complexity).to eq 1
expect(field.complexity).to eq 1
end
describe '#base_complexity' do
......@@ -43,7 +43,7 @@ RSpec.describe Types::BaseField do
it 'has specified value' do
field = described_class.new(name: 'test', type: GraphQL::Types::String, null: true, complexity: 12)
expect(field.to_graphql.complexity).to eq 12
expect(field.complexity).to eq 12
end
context 'when field has a resolver' do
......@@ -51,7 +51,7 @@ RSpec.describe Types::BaseField do
let(:field) { described_class.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: resolver, complexity: 2, max_page_size: 100, null: true) }
it 'uses this complexity' do
expect(field.to_graphql.complexity).to eq 2
expect(field.complexity).to eq 2
end
end
......@@ -59,13 +59,13 @@ RSpec.describe Types::BaseField do
let(:field) { described_class.new(name: 'test', type: GraphQL::Types::String.connection_type, resolver_class: resolver, max_page_size: 100, null: true) }
it 'sets complexity depending on arguments for resolvers' do
expect(field.to_graphql.complexity.call({}, {}, 2)).to eq 4
expect(field.to_graphql.complexity.call({}, { first: 50 }, 2)).to eq 3
expect(field.complexity.call({}, {}, 2)).to eq 4
expect(field.complexity.call({}, { first: 50 }, 2)).to eq 3
end
it 'sets complexity depending on number load limits for resolvers' do
expect(field.to_graphql.complexity.call({}, { first: 1 }, 2)).to eq 2
expect(field.to_graphql.complexity.call({}, { first: 1, foo: true }, 2)).to eq 4
expect(field.complexity.call({}, { first: 1 }, 2)).to eq 2
expect(field.complexity.call({}, { first: 1, foo: true }, 2)).to eq 4
end
end
......@@ -73,8 +73,8 @@ RSpec.describe Types::BaseField do
it 'sets complexity as normal' do
field = described_class.new(name: 'test', type: GraphQL::Types::String, resolver_class: resolver, max_page_size: 100, null: true)
expect(field.to_graphql.complexity.call({}, {}, 2)).to eq 2
expect(field.to_graphql.complexity.call({}, { first: 50 }, 2)).to eq 2
expect(field.complexity.call({}, {}, 2)).to eq 2
expect(field.complexity.call({}, { first: 50 }, 2)).to eq 2
end
end
end
......@@ -84,9 +84,9 @@ RSpec.describe Types::BaseField do
it 'adds 1 if true' do
with_gitaly_field = described_class.new(name: 'test', type: GraphQL::Types::String, resolver_class: resolver, null: true, calls_gitaly: true)
without_gitaly_field = described_class.new(name: 'test', type: GraphQL::Types::String, resolver_class: resolver, null: true)
base_result = without_gitaly_field.to_graphql.complexity.call({}, {}, 2)
base_result = without_gitaly_field.complexity.call({}, {}, 2)
expect(with_gitaly_field.to_graphql.complexity.call({}, {}, 2)).to eq base_result + 1
expect(with_gitaly_field.complexity.call({}, {}, 2)).to eq base_result + 1
end
end
......@@ -94,7 +94,7 @@ RSpec.describe Types::BaseField do
it 'adds 1 if true' do
field = described_class.new(name: 'test', type: GraphQL::Types::String, null: true, calls_gitaly: true)
expect(field.to_graphql.complexity).to eq 2
expect(field.complexity).to eq 2
end
end
......@@ -108,14 +108,14 @@ RSpec.describe Types::BaseField do
it 'has complexity set to that constant' do
field = described_class.new(name: 'test', type: GraphQL::Types::String, null: true, complexity: 12)
expect(field.to_graphql.complexity).to eq 12
expect(field.complexity).to eq 12
end
it 'does not raise an error even with Gitaly calls' do
allow(Gitlab::GitalyClient).to receive(:get_request_count).and_return([0, 1])
field = described_class.new(name: 'test', type: GraphQL::Types::String, null: true, complexity: 12)
expect(field.to_graphql.complexity).to eq 12
expect(field.complexity).to eq 12
end
end
end
......
......@@ -11,7 +11,7 @@ RSpec.describe Types::GlobalIDType do
let(:gid) { project.to_global_id }
it 'is has the correct name' do
expect(described_class.to_graphql.name).to eq('GlobalID')
expect(described_class.graphql_name).to eq('GlobalID')
end
describe '.coerce_result' do
......@@ -63,7 +63,7 @@ RSpec.describe Types::GlobalIDType do
let(:type) { ::Types::GlobalIDType[::Project] }
it 'is has the correct name' do
expect(type.to_graphql.name).to eq('ProjectID')
expect(type.graphql_name).to eq('ProjectID')
end
context 'the GID is appropriate' do
......@@ -126,7 +126,7 @@ RSpec.describe Types::GlobalIDType do
let(:deprecating_gid) { Gitlab::GlobalId.build(model_name: 'Issue', id: issue.id) }
it 'appends the description with a deprecation notice for the old Global ID' do
expect(type.to_graphql.description).to include('The older format `"gid://gitlab/OldIssue/1"` was deprecated in 10.0')
expect(type.description).to include('The older format `"gid://gitlab/OldIssue/1"` was deprecated in 10.0')
end
describe 'coercing input against the type (parsing the Global ID string when supplied as an argument)' do
......@@ -242,7 +242,7 @@ RSpec.describe Types::GlobalIDType do
let(:type) { ::Types::GlobalIDType[::Ci::Build] }
it 'is has a valid GraphQL identifier for a name' do
expect(type.to_graphql.name).to eq('CiBuildID')
expect(type.graphql_name).to eq('CiBuildID')
end
end
......
......@@ -11,7 +11,7 @@ RSpec.describe Gitlab::Graphql::MarkdownField do
expect(field.name).to eq('testHtml')
expect(field.description).to eq('The GitLab Flavored Markdown rendering of `hello`')
expect(field.type).to eq(GraphQL::Types::String)
expect(field.to_graphql.complexity).to eq(5)
expect(field.complexity).to eq(5)
end
context 'developer warnings' do
......@@ -43,7 +43,7 @@ RSpec.describe Gitlab::Graphql::MarkdownField do
let(:field) { type_class.fields['noteHtml'] }
it 'renders markdown from the same property as the field name without the `_html` suffix' do
expect(field.to_graphql.resolve(type_instance, {}, context)).to eq(expected_markdown)
expect(field.resolve(type_instance, {}, context)).to eq(expected_markdown)
end
context 'when a `method` argument is passed' do
......@@ -51,7 +51,7 @@ RSpec.describe Gitlab::Graphql::MarkdownField do
let(:field) { type_class.fields['testHtml'] }
it 'renders markdown from a specific property' do
expect(field.to_graphql.resolve(type_instance, {}, context)).to eq(expected_markdown)
expect(field.resolve(type_instance, {}, context)).to eq(expected_markdown)
end
end
......@@ -62,21 +62,21 @@ RSpec.describe Gitlab::Graphql::MarkdownField do
let(:note) { build(:note, note: "Referencing #{issue.to_reference(full: true)}") }
it 'renders markdown correctly' do
expect(field.to_graphql.resolve(type_instance, {}, context)).to include(issue_path(issue))
expect(field.resolve(type_instance, {}, context)).to include(issue_path(issue))
end
context 'when the issue is not publicly accessible' do
let_it_be(:project) { create(:project, :private) }
it 'hides the references from users that are not allowed to see the reference' do
expect(field.to_graphql.resolve(type_instance, {}, context)).not_to include(issue_path(issue))
expect(field.resolve(type_instance, {}, context)).not_to include(issue_path(issue))
end
it 'shows the reference to users that are allowed to see it' do
context = GraphQL::Query::Context.new(query: query, values: { current_user: project.first_owner }, object: nil)
type_instance = type_class.authorized_new(note, context)
expect(field.to_graphql.resolve(type_instance, {}, context)).to include(issue_path(issue))
expect(field.resolve(type_instance, {}, context)).to include(issue_path(issue))
end
end
end
......
......@@ -17,7 +17,7 @@ RSpec.describe Gitlab::Graphql::MountMutation do
f.mount_mutation(mutation)
end
mutation_type.get_field('testMutation').to_graphql
mutation_type.get_field('testMutation')
end
it 'mounts a mutation' do
......@@ -31,7 +31,7 @@ RSpec.describe Gitlab::Graphql::MountMutation do
f.mount_aliased_mutation('MyAlias', mutation)
end
mutation_type.get_field('myAlias').to_graphql
mutation_type.get_field('myAlias')
end
it 'mounts a mutation' do
......@@ -43,11 +43,11 @@ RSpec.describe Gitlab::Graphql::MountMutation do
end
it 'has a correct type' do
expect(field.type.name).to eq('MyAliasPayload')
expect(field.type.to_type_signature).to eq('MyAliasPayload')
end
it 'has a correct input argument' do
expect(field.arguments['input'].type.unwrap.name).to eq('MyAliasInput')
expect(field.arguments['input'].type.unwrap.to_type_signature).to eq('MyAliasInput')
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