summaryrefslogtreecommitdiff
path: root/lib/gitlab/etag_caching/router/graphql.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/etag_caching/router/graphql.rb')
-rw-r--r--lib/gitlab/etag_caching/router/graphql.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/etag_caching/router/graphql.rb b/lib/gitlab/etag_caching/router/graphql.rb
new file mode 100644
index 00000000000..f1737f0ce5a
--- /dev/null
+++ b/lib/gitlab/etag_caching/router/graphql.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module EtagCaching
+ module Router
+ class Graphql
+ extend EtagCaching::Router::Helpers
+ GRAPHQL_ETAG_RESOURCE_HEADER = 'X-GITLAB-GRAPHQL-RESOURCE-ETAG'
+
+ ROUTES = [
+ [
+ %r(\Apipelines/id/\d+\z),
+ 'pipelines_graph',
+ 'continuous_integration'
+ ]
+ ].map(&method(:build_route)).freeze
+
+ def self.match(request)
+ return unless request.path_info == graphql_api_path
+
+ graphql_resource = request.headers[GRAPHQL_ETAG_RESOURCE_HEADER]
+ return unless graphql_resource
+
+ ROUTES.find { |route| route.match(graphql_resource) }
+ end
+
+ def self.cache_key(request)
+ [
+ request.path,
+ request.headers[GRAPHQL_ETAG_RESOURCE_HEADER]
+ ].compact.join(':')
+ end
+
+ def self.graphql_api_path
+ @graphql_api_path ||= Gitlab::Routing.url_helpers.api_graphql_path
+ end
+ private_class_method :graphql_api_path
+ end
+ end
+ end
+end