Commit 4c4cbfae authored by Thong Kuah's avatar Thong Kuah

Merge branch 'cablett-nodes-recursion-analyzer' into 'master'

Simplify recursion fixtures and add `nodes` to recursion analyser IGNORED_FIELDS

See merge request gitlab-org/gitlab!24050
parents a70920ff 183b158e
...@@ -6,7 +6,7 @@ module Gitlab ...@@ -6,7 +6,7 @@ module Gitlab
module Graphql module Graphql
module QueryAnalyzers module QueryAnalyzers
class RecursionAnalyzer class RecursionAnalyzer
IGNORED_FIELDS = %w(node edges ofType).freeze IGNORED_FIELDS = %w(node edges nodes ofType).freeze
RECURSION_THRESHOLD = 2 RECURSION_THRESHOLD = 2
def initial_value(query) def initial_value(query)
......
query allSchemaTypes { query allSchemaTypes {
__schema { __schema {
types { types {
fields {
type{
fields {
type {
fields {
type {
fields {
type {
fields {
type {
fields {
type {
fields {
type {
fields {
type {
fields {
type {
fields {
type {
fields { fields {
type { type {
fields { fields {
...@@ -34,24 +14,4 @@ query allSchemaTypes { ...@@ -34,24 +14,4 @@ query allSchemaTypes {
} }
} }
} }
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
} }
{
project(fullPath: "gitlab-org/gitlab") {
group {
projects {
edges {
node {
group {
projects {
edges {
node {
group {
description
}
}
}
}
}
}
}
}
}
}
}
{
project(fullPath: "gitlab-org/gitlab") {
group {
projects {
nodes {
group {
projects {
nodes {
group {
description
}
}
}
}
}
}
}
}
}
{
project(fullPath: "gitlab-org/gitlab-ce") {
group {
projects {
edges {
node {
group {
projects {
edges {
node {
group {
projects {
edges {
node {
group {
projects {
edges {
node {
group {
projects {
edges {
node {
group {
description
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
...@@ -67,7 +67,12 @@ describe 'GitlabSchema configurations' do ...@@ -67,7 +67,12 @@ describe 'GitlabSchema configurations' do
end end
end end
context 'a deep but simple recursive introspective query' do context 'failing queries' do
before do
allow(GitlabSchema).to receive(:max_query_recursion).and_return 1
end
context 'a recursive introspective query' do
it 'fails due to recursion' do it 'fails due to recursion' do
query = File.read(Rails.root.join('spec/fixtures/api/graphql/recursive-introspection.graphql')) query = File.read(Rails.root.join('spec/fixtures/api/graphql/recursive-introspection.graphql'))
...@@ -77,16 +82,32 @@ describe 'GitlabSchema configurations' do ...@@ -77,16 +82,32 @@ describe 'GitlabSchema configurations' do
end end
end end
context 'a deep recursive non-introspective query' do context 'a recursive non-introspective query' do
it 'fails due to recursion, complexity and depth' do before do
allow(GitlabSchema).to receive(:max_query_complexity).and_return 1 allow(GitlabSchema).to receive(:max_query_complexity).and_return 1
query = File.read(Rails.root.join('spec/fixtures/api/graphql/recursive-query.graphql')) allow(GitlabSchema).to receive(:max_query_depth).and_return 1
allow(GitlabSchema).to receive(:max_query_complexity).and_return 1
end
shared_examples 'fails due to recursion, complexity and depth' do |fixture_file|
it 'fails due to recursion, complexity and depth' do
query = File.read(Rails.root.join(fixture_file))
post_graphql(query, current_user: nil) post_graphql(query, current_user: nil)
expect_graphql_errors_to_include [/Recursive query/, /exceeds max complexity/, /exceeds max depth/] expect_graphql_errors_to_include [/Recursive query/, /exceeds max complexity/, /exceeds max depth/]
end end
end end
context 'using `nodes` notation' do
it_behaves_like 'fails due to recursion, complexity and depth', 'spec/fixtures/api/graphql/recursive-query-nodes.graphql'
end
context 'using `edges -> node` notation' do
it_behaves_like 'fails due to recursion, complexity and depth', 'spec/fixtures/api/graphql/recursive-query-edges-node.graphql'
end
end
end
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