diff options
author | Phil Hughes <me@iamphill.com> | 2019-05-09 10:27:07 +0100 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-05-28 10:22:02 +0200 |
commit | 11f85ae8c3b8ec5d864edd079e7c420a49cae72e (patch) | |
tree | 8da63219fc0977c7e132f7177bff20f41c997520 /app/graphql | |
parent | 2cc6e6ff2628bd71faa71f083646a981ab2bcc11 (diff) | |
download | gitlab-ce-11f85ae8c3b8ec5d864edd079e7c420a49cae72e.tar.gz |
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.
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/gitlab_schema.rb | 15 |
1 files changed, 13 insertions, 2 deletions
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 |