2019-03-03 07:53:03 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe 'GraphQL' do
|
2019-03-03 07:53:03 -05:00
|
|
|
include GraphqlHelpers
|
2021-03-23 23:09:04 -04:00
|
|
|
include AfterNextHelpers
|
2019-03-03 07:53:03 -05:00
|
|
|
|
2021-03-23 23:09:04 -04:00
|
|
|
let(:query) { graphql_query_for('echo', text: 'Hello world') }
|
2021-07-01 17:08:38 -04:00
|
|
|
let(:mutation) { 'mutation { echoCreate(input: { messages: ["hello", "world"] }) { echoes } }' }
|
|
|
|
|
|
|
|
let_it_be(:user) { create(:user) }
|
2019-03-03 07:53:03 -05:00
|
|
|
|
2021-03-23 23:09:04 -04:00
|
|
|
describe 'logging' do
|
2019-05-23 17:29:19 -04:00
|
|
|
shared_examples 'logging a graphql query' do
|
2021-10-29 11:11:56 -04:00
|
|
|
let(:expected_execute_query_log) do
|
2020-10-01 23:08:28 -04:00
|
|
|
{
|
2021-10-29 11:11:56 -04:00
|
|
|
"correlation_id" => kind_of(String),
|
2021-11-09 07:12:15 -05:00
|
|
|
"meta.caller_id" => "graphql:anonymous",
|
2021-10-29 11:11:56 -04:00
|
|
|
"meta.client_id" => kind_of(String),
|
|
|
|
"meta.feature_category" => "not_owned",
|
|
|
|
"meta.remote_ip" => kind_of(String),
|
|
|
|
"query_analysis.duration_s" => kind_of(Numeric),
|
|
|
|
"query_analysis.depth" => 1,
|
|
|
|
"query_analysis.complexity" => 1,
|
|
|
|
"query_analysis.used_fields" => ['Query.echo'],
|
|
|
|
"query_analysis.used_deprecated_fields" => [],
|
|
|
|
# query_fingerprint starts with operation name
|
|
|
|
query_fingerprint: %r{^anonymous\/},
|
|
|
|
duration_s: kind_of(Numeric),
|
|
|
|
trace_type: 'execute_query',
|
2021-03-23 14:09:05 -04:00
|
|
|
operation_name: nil,
|
2021-10-29 11:11:56 -04:00
|
|
|
# operation_fingerprint starts with operation name
|
|
|
|
operation_fingerprint: %r{^anonymous\/},
|
|
|
|
is_mutation: false,
|
2021-11-04 05:12:56 -04:00
|
|
|
variables: variables.to_s,
|
2021-10-29 11:11:56 -04:00
|
|
|
query_string: query
|
2020-10-01 23:08:28 -04:00
|
|
|
}
|
2019-05-23 17:29:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs a query with the expected params' do
|
2021-10-29 11:11:56 -04:00
|
|
|
expect(Gitlab::GraphqlLogger).to receive(:info).with(expected_execute_query_log).once
|
2019-05-23 18:43:47 -04:00
|
|
|
|
2019-05-23 17:29:19 -04:00
|
|
|
post_graphql(query, variables: variables)
|
|
|
|
end
|
|
|
|
|
2019-05-23 18:43:47 -04:00
|
|
|
it 'does not instantiate any query analyzers' do # they are static and re-used
|
|
|
|
expect(GraphQL::Analysis::QueryComplexity).not_to receive(:new)
|
|
|
|
expect(GraphQL::Analysis::QueryDepth).not_to receive(:new)
|
|
|
|
|
|
|
|
2.times { post_graphql(query, variables: variables) }
|
|
|
|
end
|
2019-05-02 03:09:10 -04:00
|
|
|
end
|
2019-05-01 20:16:49 -04:00
|
|
|
|
2019-05-02 03:09:10 -04:00
|
|
|
context 'with no variables' do
|
2019-05-23 17:29:19 -04:00
|
|
|
let(:variables) { {} }
|
2019-05-02 03:09:10 -04:00
|
|
|
|
2019-05-23 17:29:19 -04:00
|
|
|
it_behaves_like 'logging a graphql query'
|
2019-05-01 20:16:49 -04:00
|
|
|
end
|
|
|
|
|
2019-05-02 03:09:10 -04:00
|
|
|
context 'with variables' do
|
2019-05-23 17:29:19 -04:00
|
|
|
let(:variables) do
|
2019-05-22 01:13:06 -04:00
|
|
|
{ "foo" => "bar" }
|
2019-05-02 03:09:10 -04:00
|
|
|
end
|
|
|
|
|
2019-05-23 17:29:19 -04:00
|
|
|
it_behaves_like 'logging a graphql query'
|
2019-05-02 03:09:10 -04:00
|
|
|
end
|
2019-05-23 18:43:47 -04:00
|
|
|
|
|
|
|
context 'when there is an error in the logger' do
|
|
|
|
before do
|
2021-03-23 23:09:04 -04:00
|
|
|
logger_analyzer = GitlabSchema.query_analyzers.find do |qa|
|
|
|
|
qa.is_a? Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer
|
|
|
|
end
|
|
|
|
allow(logger_analyzer).to receive(:process_variables)
|
|
|
|
.and_raise(StandardError.new("oh noes!"))
|
2019-05-23 18:43:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs the exception in Sentry and continues with the request' do
|
2021-03-23 23:09:04 -04:00
|
|
|
expect(Gitlab::ErrorTracking)
|
|
|
|
.to receive(:track_and_raise_for_dev_exception).at_least(:once)
|
|
|
|
expect(Gitlab::GraphqlLogger)
|
|
|
|
.to receive(:info)
|
2019-05-23 18:43:47 -04:00
|
|
|
|
|
|
|
post_graphql(query, variables: {})
|
|
|
|
end
|
|
|
|
end
|
2019-05-01 20:16:49 -04:00
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
context 'when executing mutations' do
|
|
|
|
let(:mutation_with_variables) do
|
|
|
|
<<~GQL
|
|
|
|
mutation($a: String!, $b: String!) {
|
|
|
|
echoCreate(input: { messages: [$a, $b] }) { echoes }
|
|
|
|
}
|
|
|
|
GQL
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with POST' do
|
|
|
|
it 'succeeds' do
|
|
|
|
post_graphql(mutation, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_data_at(:echo_create, :echoes)).to eq %w[hello world]
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with variables' do
|
|
|
|
it 'succeeds' do
|
|
|
|
post_graphql(mutation_with_variables, current_user: user, variables: { a: 'Yo', b: 'there' })
|
|
|
|
|
|
|
|
expect(graphql_data_at(:echo_create, :echoes)).to eq %w[Yo there]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with GET' do
|
|
|
|
it 'fails' do
|
|
|
|
get_graphql(mutation, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_errors).to include(a_hash_including('message' => /Mutations are forbidden/))
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with variables' do
|
|
|
|
it 'fails' do
|
|
|
|
get_graphql(mutation_with_variables, current_user: user, variables: { a: 'Yo', b: 'there' })
|
|
|
|
|
|
|
|
expect(graphql_errors).to include(a_hash_including('message' => /Mutations are forbidden/))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when executing queries' do
|
|
|
|
context 'with POST' do
|
|
|
|
it 'succeeds' do
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_data_at(:echo)).to include 'Hello world'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with GET' do
|
|
|
|
it 'succeeds' do
|
|
|
|
get_graphql(query, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_data_at(:echo)).to include 'Hello world'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting a query by operation name' do
|
|
|
|
let(:query) { "query A #{graphql_query_for('echo', text: 'Hello world')}" }
|
|
|
|
let(:mutation) { 'mutation B { echoCreate(input: { messages: ["hello", "world"] }) { echoes } }' }
|
|
|
|
|
|
|
|
let(:combined) { [query, mutation].join("\n\n") }
|
|
|
|
|
|
|
|
context 'with POST' do
|
|
|
|
it 'succeeds when selecting the query' do
|
|
|
|
post_graphql(combined, current_user: user, params: { operationName: 'A' })
|
|
|
|
|
|
|
|
resp = json_response
|
|
|
|
|
|
|
|
expect(resp.dig('data', 'echo')).to include 'Hello world'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'succeeds when selecting the mutation' do
|
|
|
|
post_graphql(combined, current_user: user, params: { operationName: 'B' })
|
|
|
|
|
|
|
|
resp = json_response
|
|
|
|
|
|
|
|
expect(resp.dig('data', 'echoCreate', 'echoes')).to eq %w[hello world]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with GET' do
|
|
|
|
it 'succeeds when selecting the query' do
|
|
|
|
get_graphql(combined, current_user: user, params: { operationName: 'A' })
|
|
|
|
|
|
|
|
resp = json_response
|
|
|
|
|
|
|
|
expect(resp.dig('data', 'echo')).to include 'Hello world'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails when selecting the mutation' do
|
|
|
|
get_graphql(combined, current_user: user, params: { operationName: 'B' })
|
|
|
|
|
|
|
|
resp = json_response
|
|
|
|
|
|
|
|
expect(resp.dig('errors', 0, 'message')).to include "Mutations are forbidden"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when batching mutations and queries' do
|
|
|
|
let(:batched) do
|
|
|
|
[
|
|
|
|
{ query: "query A #{graphql_query_for('echo', text: 'Hello world')}" },
|
|
|
|
{ query: 'mutation B { echoCreate(input: { messages: ["hello", "world"] }) { echoes } }' }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with POST' do
|
|
|
|
it 'succeeds' do
|
|
|
|
post_multiplex(batched, current_user: user)
|
|
|
|
|
|
|
|
resp = json_response
|
|
|
|
|
|
|
|
expect(resp.dig(0, 'data', 'echo')).to include 'Hello world'
|
|
|
|
expect(resp.dig(1, 'data', 'echoCreate', 'echoes')).to eq %w[hello world]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with GET' do
|
|
|
|
it 'fails with a helpful error message' do
|
|
|
|
get_multiplex(batched, current_user: user)
|
|
|
|
|
|
|
|
resp = json_response
|
|
|
|
|
|
|
|
expect(resp.dig('errors', 0, 'message')).to include "Mutations are forbidden"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-23 23:09:04 -04:00
|
|
|
context 'with invalid variables' do
|
2019-03-03 07:53:03 -05:00
|
|
|
it 'returns an error' do
|
|
|
|
post_graphql(query, variables: "This is not JSON")
|
|
|
|
|
2020-02-25 07:08:48 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:unprocessable_entity)
|
2019-03-03 07:53:03 -05:00
|
|
|
expect(json_response['errors'].first['message']).not_to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-23 23:09:04 -04:00
|
|
|
describe 'authentication', :allow_forgery_protection do
|
2019-03-03 07:53:03 -05:00
|
|
|
it 'allows access to public data without authentication' do
|
|
|
|
post_graphql(query)
|
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq('nil says: Hello world')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not authenticate a user with an invalid CSRF' do
|
|
|
|
login_as(user)
|
|
|
|
|
|
|
|
post_graphql(query, headers: { 'X-CSRF-Token' => 'invalid' })
|
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq('nil says: Hello world')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'authenticates a user with a valid session token' do
|
|
|
|
# Create a session to get a CSRF token from
|
|
|
|
login_as(user)
|
|
|
|
get('/')
|
|
|
|
|
2021-04-22 17:09:53 -04:00
|
|
|
post '/api/graphql', params: { query: query }, headers: { 'X-CSRF-Token' => session['_csrf_token'] }
|
2019-03-03 07:53:03 -05:00
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq("\"#{user.username}\" says: Hello world")
|
|
|
|
end
|
|
|
|
|
2021-03-23 23:09:04 -04:00
|
|
|
context 'with token authentication' do
|
2022-01-11 19:16:35 -05:00
|
|
|
let(:token) { create(:personal_access_token, user: user) }
|
2019-03-03 07:53:03 -05:00
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'authenticates users with a PAT' do
|
2019-03-03 07:53:03 -05:00
|
|
|
stub_authentication_activity_metrics(debug: false)
|
|
|
|
|
|
|
|
expect(authentication_metrics)
|
|
|
|
.to increment(:user_authenticated_counter)
|
|
|
|
.and increment(:user_session_override_counter)
|
|
|
|
.and increment(:user_sessionless_authentication_counter)
|
|
|
|
|
|
|
|
post_graphql(query, headers: { 'PRIVATE-TOKEN' => token.token })
|
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq("\"#{token.user.username}\" says: Hello world")
|
|
|
|
end
|
|
|
|
|
2021-07-01 17:08:38 -04:00
|
|
|
it 'prevents access by deactived users' do
|
|
|
|
token.user.deactivate!
|
|
|
|
|
|
|
|
post_graphql(query, headers: { 'PRIVATE-TOKEN' => token.token })
|
|
|
|
|
|
|
|
expect(graphql_errors).to include({ 'message' => /API not accessible/ })
|
|
|
|
end
|
|
|
|
|
2022-01-11 19:16:35 -05:00
|
|
|
context 'when user with expired password' do
|
|
|
|
let_it_be(:user) { create(:user, password_expires_at: 2.minutes.ago) }
|
|
|
|
|
|
|
|
it 'does not authenticate user' do
|
|
|
|
post_graphql(query, headers: { 'PRIVATE-TOKEN' => token.token })
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq('nil says: Hello world')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when password expiration is not applicable' do
|
|
|
|
context 'when ldap user' do
|
|
|
|
let_it_be(:user) { create(:omniauth_user, provider: 'ldap', password_expires_at: 2.minutes.ago) }
|
|
|
|
|
|
|
|
it 'authenticates user' do
|
|
|
|
post_graphql(query, headers: { 'PRIVATE-TOKEN' => token.token })
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq("\"#{token.user.username}\" says: Hello world")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-03 07:53:03 -05:00
|
|
|
context 'when the personal access token has no api scope' do
|
|
|
|
it 'does not log the user in' do
|
2021-03-23 23:09:04 -04:00
|
|
|
token.update!(scopes: [:read_user])
|
2019-03-03 07:53:03 -05:00
|
|
|
|
|
|
|
post_graphql(query, headers: { 'PRIVATE-TOKEN' => token.token })
|
|
|
|
|
2020-02-25 07:08:48 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-03-03 07:53:03 -05:00
|
|
|
|
|
|
|
expect(graphql_data['echo']).to eq('nil says: Hello world')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-06-21 10:20:00 -04:00
|
|
|
|
|
|
|
describe 'testing for Gitaly calls' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:query) do
|
2021-03-23 23:09:04 -04:00
|
|
|
graphql_query_for(
|
|
|
|
:project,
|
|
|
|
{ full_path: project.full_path },
|
|
|
|
'id'
|
|
|
|
)
|
2019-06-21 10:20:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a working graphql query' do
|
|
|
|
before do
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Gitaly is called' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::GitalyClient).to receive(:get_request_count).and_return(1, 2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "logs a warning that the 'calls_gitaly' field declaration is missing" do
|
2019-12-16 07:07:43 -05:00
|
|
|
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).once
|
2019-06-21 10:20:00 -04:00
|
|
|
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-26 04:08:47 -05:00
|
|
|
|
|
|
|
describe 'resolver complexity' do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2020-02-26 04:08:47 -05:00
|
|
|
let(:query) do
|
|
|
|
graphql_query_for(
|
|
|
|
'project',
|
|
|
|
{ 'fullPath' => project.full_path },
|
|
|
|
query_graphql_field(resource, {}, 'edges { node { iid } }')
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('GitlabSchema::DEFAULT_MAX_COMPLEXITY', 6)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fetching single resource' do
|
|
|
|
let(:resource) { 'issues(first: 1)' }
|
|
|
|
|
|
|
|
it 'processes the query' do
|
|
|
|
post_graphql(query)
|
|
|
|
|
|
|
|
expect(graphql_errors).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when fetching too many resources' do
|
|
|
|
let(:resource) { 'issues(first: 100)' }
|
|
|
|
|
|
|
|
it 'returns an error' do
|
|
|
|
post_graphql(query)
|
|
|
|
|
|
|
|
expect_graphql_errors_to_include(/which exceeds max complexity/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2021-04-06 11:09:23 -04:00
|
|
|
describe 'complexity limits' do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2021-04-06 11:09:23 -04:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
|
|
|
let(:query_fields) do
|
|
|
|
<<~QUERY
|
|
|
|
id
|
|
|
|
QUERY
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
graphql_query_for(
|
|
|
|
'project',
|
|
|
|
{ 'fullPath' => project.full_path },
|
|
|
|
query_fields
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_const('GitlabSchema::DEFAULT_MAX_COMPLEXITY', 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unauthenticated user' do
|
|
|
|
subject { post_graphql(query) }
|
|
|
|
|
|
|
|
it 'raises a complexity error' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect_graphql_errors_to_include(/which exceeds max complexity/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authenticated user' do
|
|
|
|
subject { post_graphql(query, current_user: user) }
|
|
|
|
|
2021-08-08 23:10:10 -04:00
|
|
|
it 'does not raise an error as it uses the `AUTHENTICATED_MAX_COMPLEXITY`' do
|
2021-04-06 11:09:23 -04:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(graphql_errors).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-16 17:08:20 -04:00
|
|
|
describe 'keyset pagination' do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
let_it_be(:issues) { create_list(:issue, 10, project: project, created_at: Time.now.change(usec: 200)) }
|
|
|
|
|
|
|
|
let(:page_size) { 6 }
|
2021-03-23 23:09:04 -04:00
|
|
|
let(:issues_edges) { %w[project issues edges] }
|
|
|
|
let(:end_cursor) { %w[project issues pageInfo endCursor] }
|
2020-06-16 17:08:20 -04:00
|
|
|
let(:query) do
|
|
|
|
<<~GRAPHQL
|
|
|
|
query project($fullPath: ID!, $first: Int, $after: String) {
|
|
|
|
project(fullPath: $fullPath) {
|
|
|
|
issues(first: $first, after: $after) {
|
|
|
|
edges { node { iid } }
|
|
|
|
pageInfo { endCursor }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute_query(after: nil)
|
2021-03-23 23:09:04 -04:00
|
|
|
post_graphql(
|
2020-06-16 17:08:20 -04:00
|
|
|
query,
|
2021-03-23 23:09:04 -04:00
|
|
|
current_user: nil,
|
2020-06-16 17:08:20 -04:00
|
|
|
variables: {
|
|
|
|
fullPath: project.full_path,
|
|
|
|
first: page_size,
|
|
|
|
after: after
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-04-22 05:09:45 -04:00
|
|
|
context 'when new_graphql_keyset_pagination feature flag is off' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(new_graphql_keyset_pagination: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'paginates datetimes correctly when they have millisecond data' do
|
|
|
|
# let's make sure we're actually querying a timestamp, just in case
|
|
|
|
expect(Gitlab::Graphql::Pagination::Keyset::QueryBuilder)
|
|
|
|
.to receive(:new).with(anything, anything, hash_including('created_at'), anything).and_call_original
|
|
|
|
|
|
|
|
execute_query
|
|
|
|
first_page = graphql_data
|
|
|
|
edges = first_page.dig(*issues_edges)
|
|
|
|
cursor = first_page.dig(*end_cursor)
|
|
|
|
|
|
|
|
expect(edges.count).to eq(6)
|
|
|
|
expect(edges.last['node']['iid']).to eq(issues[4].iid.to_s)
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2021-04-22 05:09:45 -04:00
|
|
|
execute_query(after: cursor)
|
|
|
|
second_page = graphql_data
|
|
|
|
edges = second_page.dig(*issues_edges)
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2021-04-22 05:09:45 -04:00
|
|
|
expect(edges.count).to eq(4)
|
|
|
|
expect(edges.last['node']['iid']).to eq(issues[0].iid.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_graphql_keyset_pagination feature flag is on' do
|
|
|
|
it 'paginates datetimes correctly when they have millisecond data' do
|
|
|
|
execute_query
|
|
|
|
first_page = graphql_data
|
|
|
|
edges = first_page.dig(*issues_edges)
|
|
|
|
cursor = first_page.dig(*end_cursor)
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2021-04-22 05:09:45 -04:00
|
|
|
expect(edges.count).to eq(6)
|
|
|
|
expect(edges.last['node']['iid']).to eq(issues[4].iid.to_s)
|
2020-06-16 17:08:20 -04:00
|
|
|
|
2021-04-22 05:09:45 -04:00
|
|
|
execute_query(after: cursor)
|
|
|
|
second_page = graphql_data
|
|
|
|
edges = second_page.dig(*issues_edges)
|
|
|
|
|
|
|
|
expect(edges.count).to eq(4)
|
|
|
|
expect(edges.last['node']['iid']).to eq(issues[0].iid.to_s)
|
|
|
|
end
|
2020-06-16 17:08:20 -04:00
|
|
|
end
|
|
|
|
end
|
2019-03-03 07:53:03 -05:00
|
|
|
end
|