summaryrefslogtreecommitdiff
path: root/app/graphql
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2019-06-06 11:54:30 +0000
committerJan Provaznik <jprovaznik@gitlab.com>2019-06-06 11:54:30 +0000
commit9318fba9cb352e91c9f45513c814bc5f7e18057f (patch)
tree8e097b516fdb2705ff4e4b7d91de70e4b5021d30 /app/graphql
parent102c0e81fc7f90f4a57bfba30f554423f9d04802 (diff)
parent0cedd43ef7aca863cbe41a544ce735c75390a5fb (diff)
downloadgitlab-ce-9318fba9cb352e91c9f45513c814bc5f7e18057f.tar.gz
Merge branch '62706-graphql-complexity-values-are-incorrectly-doubled' into 'master'
Reduce GraphQL complexity for non-connection fields Closes #62706 See merge request gitlab-org/gitlab-ce!29165
Diffstat (limited to 'app/graphql')
-rw-r--r--app/graphql/types/base_field.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/app/graphql/types/base_field.rb b/app/graphql/types/base_field.rb
index a374851e835..dd0d9105df6 100644
--- a/app/graphql/types/base_field.rb
+++ b/app/graphql/types/base_field.rb
@@ -29,15 +29,18 @@ module Types
# proc because we set complexity depending on arguments and number of
# items which can be loaded.
proc do |ctx, args, child_complexity|
- page_size = @max_page_size || ctx.schema.default_max_page_size
- limit_value = [args[:first], args[:last], page_size].compact.min
-
# Resolvers may add extra complexity depending on used arguments
complexity = child_complexity + self.resolver&.try(:resolver_complexity, args, child_complexity: child_complexity).to_i
- # Resolvers may add extra complexity depending on number of items being loaded.
- multiplier = self.resolver&.try(:complexity_multiplier, args).to_f
- complexity += complexity * limit_value * multiplier
+ field_defn = to_graphql
+
+ if field_defn.connection?
+ # Resolvers may add extra complexity depending on number of items being loaded.
+ page_size = field_defn.connection_max_page_size || ctx.schema.default_max_page_size
+ limit_value = [args[:first], args[:last], page_size].compact.min
+ multiplier = self.resolver&.try(:complexity_multiplier, args).to_f
+ complexity += complexity * limit_value * multiplier
+ end
complexity.to_i
end