diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /lib/gitlab/graphql/queries.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'lib/gitlab/graphql/queries.rb')
-rw-r--r-- | lib/gitlab/graphql/queries.rb | 14 |
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) |