9
9
10
10
use Magento \Framework \App \FrontControllerInterface ;
11
11
use Magento \Framework \App \RequestInterface ;
12
+ use Magento \Framework \App \Response \Http as ResponseHttp ;
12
13
use Magento \Framework \App \ResponseInterface ;
14
+ use Magento \Framework \Controller \ResultInterface ;
13
15
use Magento \Framework \Registry ;
14
16
use Magento \GraphQl \Controller \HttpRequestProcessor ;
15
17
use Magento \GraphQlCache \Model \CacheableQuery ;
@@ -53,6 +55,11 @@ class GraphQl
53
55
*/
54
56
private $ logger ;
55
57
58
+ /**
59
+ * @var RequestInterface
60
+ */
61
+ private $ request ;
62
+
56
63
/**
57
64
* @param CacheableQuery $cacheableQuery
58
65
* @param CacheIdCalculator $cacheIdCalculator
@@ -96,26 +103,24 @@ public function beforeDispatch(
96
103
}
97
104
/** @var \Magento\Framework\App\Request\Http $request */
98
105
$ this ->requestProcessor ->processHeaders ($ request );
106
+ $ this ->request = $ request ;
99
107
}
100
108
101
109
/**
102
- * Set cache headers after dispatch
110
+ * Plugin for GraphQL after render from dispatch to set tag and cache headers
103
111
*
104
- * @param FrontControllerInterface $subject
105
- * @param ResponseInterface $response
106
- * @param RequestInterface $request
107
- * @return ResponseInterface
112
+ * @param ResultInterface $subject
113
+ * @param ResultInterface $result
114
+ * @param ResponseHttp $response
115
+ * @return ResultInterface
108
116
*
109
117
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
110
118
*/
111
- public function afterDispatch (
112
- FrontControllerInterface $ subject ,
113
- $ response ,
114
- RequestInterface $ request
115
- ) {
116
- if (!$ this ->config ->isEnabled () || str_contains ($ request ->getContent (), 'mutation ' )) {
119
+ public function afterRenderResult (ResultInterface $ subject , ResultInterface $ result , ResponseHttp $ response )
120
+ {
121
+ if (!$ this ->config ->isEnabled () || $ this ->request && str_contains ($ this ->request ->getContent (), 'mutation ' )) {
117
122
$ response ->setNoCacheHeaders ();
118
- return $ response ;
123
+ return $ result ;
119
124
}
120
125
121
126
/** @see \Magento\Framework\App\Http::launch */
@@ -128,12 +133,12 @@ public function afterDispatch(
128
133
}
129
134
if (!$ this ->cacheableQuery ->shouldPopulateCacheHeadersWithTags ()) {
130
135
$ response ->setNoCacheHeaders ();
131
- return $ response ;
136
+ return $ result ;
132
137
}
133
138
134
139
$ response ->setPublicHeaders ($ this ->config ->getTtl ());
135
140
$ response ->setHeader ('X-Magento-Tags ' , implode (', ' , $ this ->cacheableQuery ->getCacheTags ()), true );
136
141
137
- return $ response ;
142
+ return $ result ;
138
143
}
139
144
}
0 commit comments