diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb index 7e3c09440a24ed5f3654f60755c459761418b39e..53efd9042b19543820784c97189e43d09450cf6b 100644 --- a/app/graphql/gitlab_schema.rb +++ b/app/graphql/gitlab_schema.rb @@ -31,7 +31,7 @@ class GitlabSchema < GraphQL::Schema end def self.max_query_complexity(ctx) - current_user = ctx&.fetch(:current_user) + current_user = ctx&.fetch(:current_user, nil) if current_user&.admin ADMIN_COMPLEXITY diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index a535d9cdc7e1d8fb9bd84c09ca7afb37d1aa636f..74e93b2c4df220a990eab009c34d3e74e74c12e4 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -34,12 +34,22 @@ describe GitlabSchema do end context 'for different types of users' do - it 'returns DEFAULT_MAX_COMPLEXITY for no user' do - expect(GraphQL::Schema).to receive(:execute).with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY)) + it 'returns DEFAULT_MAX_COMPLEXITY for no context' do + expect(GraphQL::Schema) + .to receive(:execute) + .with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY)) described_class.execute('query') end + it 'returns DEFAULT_MAX_COMPLEXITY for no user' do + expect(GraphQL::Schema) + .to receive(:execute) + .with('query', hash_including(max_complexity: GitlabSchema::DEFAULT_MAX_COMPLEXITY)) + + described_class.execute('query', context: {}) + end + it 'returns AUTHENTICATED_COMPLEXITY for a logged in user' do user = build :user