Commit 62235af2 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'chore/method-rename' into 'master'

Rename `conditionally_graphql!` to `run_graphql!`

Closes #32129

See merge request gitlab-org/gitlab!17724
parents c56e57d1 bbb83096
...@@ -6,7 +6,7 @@ module API ...@@ -6,7 +6,7 @@ module API
# against the graphql API. Helper code for the graphql server implementation # against the graphql API. Helper code for the graphql server implementation
# should be in app/graphql/ or lib/gitlab/graphql/ # should be in app/graphql/ or lib/gitlab/graphql/
module GraphqlHelpers module GraphqlHelpers
def conditionally_graphql!(fallback:, query:, context: {}, transform: nil) def run_graphql!(query:, context: {}, transform: nil)
result = GitlabSchema.execute(query, context: context) result = GitlabSchema.execute(query, context: context)
if transform if transform
......
...@@ -19,11 +19,10 @@ module API ...@@ -19,11 +19,10 @@ module API
detail 'This feature was introduced in GitLab 8.13.' detail 'This feature was introduced in GitLab 8.13.'
end end
get '/version' do get '/version' do
conditionally_graphql!( run_graphql!(
query: METADATA_QUERY, query: METADATA_QUERY,
context: { current_user: current_user }, context: { current_user: current_user },
transform: ->(result) { result.dig('data', 'metadata') }, transform: ->(result) { result.dig('data', 'metadata') }
fallback: -> { { version: Gitlab::VERSION, revision: Gitlab.revision } }
) )
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
describe API::Helpers::GraphqlHelpers do
describe 'run_graphql!' do
let(:query) { '{ metadata { version } }' }
let(:graphql_helper) do
Class.new do
include API::Helpers::GraphqlHelpers
end.new
end
context 'when transform function is provided' do
let(:result) { { 'data' => { 'metadata' => { 'version' => '1.0.0' } } } }
before do
allow(GitlabSchema).to receive(:execute).and_return(result)
end
it 'returns the expected result' do
expect(
graphql_helper.run_graphql!(
query: query,
transform: ->(result) { result.dig('data', 'metadata') }
)
).to eq({ 'version' => '1.0.0' })
end
end
context 'when a transform function is not provided' do
let(:result) { double('result') }
before do
allow(GitlabSchema).to receive(:execute).and_return(result)
end
it 'returns the expected result' do
expect(graphql_helper.run_graphql!(query: query)).to eq(result)
end
end
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