summaryrefslogtreecommitdiff
path: root/lib/gitlab/graphql/queries.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/graphql/queries.rb')
-rw-r--r--lib/gitlab/graphql/queries.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/queries.rb b/lib/gitlab/graphql/queries.rb
index de971743490..fcf293fb13e 100644
--- a/lib/gitlab/graphql/queries.rb
+++ b/lib/gitlab/graphql/queries.rb
@@ -145,6 +145,20 @@ module Gitlab
return redacted if printer.fields_printed > 0
end
+ def complexity(schema)
+ # See BaseResolver::resolver_complexity
+ # we want to see the max possible complexity.
+ fake_args = Struct
+ .new(:if, :keyword_arguments)
+ .new(nil, { sort: true, search: true })
+
+ query = GraphQL::Query.new(schema, text)
+ # We have no arguments, so fake them.
+ query.define_singleton_method(:arguments_for) { |_x, _y| fake_args }
+
+ GraphQL::Analysis::AST.analyze_query(query, [GraphQL::Analysis::AST::QueryComplexity]).first
+ end
+
def query
return @query if defined?(@query)