From 11f85ae8c3b8ec5d864edd079e7c420a49cae72e Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 9 May 2019 10:27:07 +0100 Subject: Enables GraphQL batch requests Enabling GraphQL batch requests allows for multiple queries to be sent in 1 request reducing the amount of requests we send to the server. Responses come come back in the same order as the queries were provided. --- app/graphql/gitlab_schema.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'app/graphql') diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb index 897e12c1b56..a63f45f231c 100644 --- a/app/graphql/gitlab_schema.rb +++ b/app/graphql/gitlab_schema.rb @@ -7,7 +7,7 @@ class GitlabSchema < GraphQL::Schema AUTHENTICATED_COMPLEXITY = 250 ADMIN_COMPLEXITY = 300 - ANONYMOUS_MAX_DEPTH = 10 + DEFAULT_MAX_DEPTH = 10 AUTHENTICATED_MAX_DEPTH = 15 use BatchLoader::GraphQL @@ -23,10 +23,21 @@ class GitlabSchema < GraphQL::Schema default_max_page_size 100 max_complexity DEFAULT_MAX_COMPLEXITY + max_depth DEFAULT_MAX_DEPTH mutation(Types::MutationType) class << self + def multiplex(queries, **kwargs) + kwargs[:max_complexity] ||= max_query_complexity(kwargs[:context]) + + queries.each do |query| + query[:max_depth] = max_query_depth(kwargs[:context]) + end + + super(queries, **kwargs) + end + def execute(query_str = nil, **kwargs) kwargs[:max_complexity] ||= max_query_complexity(kwargs[:context]) kwargs[:max_depth] ||= max_query_depth(kwargs[:context]) @@ -54,7 +65,7 @@ class GitlabSchema < GraphQL::Schema if current_user AUTHENTICATED_MAX_DEPTH else - ANONYMOUS_MAX_DEPTH + DEFAULT_MAX_DEPTH end end end -- cgit v1.2.1