2121use Magento \Framework \GraphQl \Query \Fields as QueryFields ;
2222use Magento \Framework \Controller \Result \JsonFactory ;
2323use Magento \Framework \App \ObjectManager ;
24+ use Magento \GraphQl \Model \Query \ContextFactoryInterface ;
2425
2526/**
2627 * Front controller for web API GraphQL area.
@@ -58,6 +59,7 @@ class GraphQl implements FrontControllerInterface
5859
5960 /**
6061 * @var ContextInterface
62+ * @deprecated $contextFactory is used for creating Context object
6163 */
6264 private $ resolverContext ;
6365
@@ -81,17 +83,23 @@ class GraphQl implements FrontControllerInterface
8183 */
8284 private $ httpResponse ;
8385
86+ /**
87+ * @var ContextFactoryInterface
88+ */
89+ private $ contextFactory ;
90+
8491 /**
8592 * @param Response $response
8693 * @param SchemaGeneratorInterface $schemaGenerator
8794 * @param SerializerInterface $jsonSerializer
8895 * @param QueryProcessor $queryProcessor
8996 * @param ExceptionFormatter $graphQlError
90- * @param ContextInterface $resolverContext
97+ * @param ContextInterface $resolverContext Deprecated. $contextFactory is used for creating Context object.
9198 * @param HttpRequestProcessor $requestProcessor
9299 * @param QueryFields $queryFields
93100 * @param JsonFactory|null $jsonFactory
94101 * @param HttpResponse|null $httpResponse
102+ * @param ContextFactoryInterface $contextFactory
95103 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
96104 */
97105 public function __construct (
@@ -104,7 +112,8 @@ public function __construct(
104112 HttpRequestProcessor $ requestProcessor ,
105113 QueryFields $ queryFields ,
106114 JsonFactory $ jsonFactory = null ,
107- HttpResponse $ httpResponse = null
115+ HttpResponse $ httpResponse = null ,
116+ ContextFactoryInterface $ contextFactory = null
108117 ) {
109118 $ this ->response = $ response ;
110119 $ this ->schemaGenerator = $ schemaGenerator ;
@@ -116,6 +125,7 @@ public function __construct(
116125 $ this ->queryFields = $ queryFields ;
117126 $ this ->jsonFactory = $ jsonFactory ?: ObjectManager::getInstance ()->get (JsonFactory::class);
118127 $ this ->httpResponse = $ httpResponse ?: ObjectManager::getInstance ()->get (HttpResponse::class);
128+ $ this ->contextFactory = $ contextFactory ?: ObjectManager::getInstance ()->get (ContextFactoryInterface::class);
119129 }
120130
121131 /**
@@ -144,7 +154,7 @@ public function dispatch(RequestInterface $request) : ResponseInterface
144154 $ result = $ this ->queryProcessor ->process (
145155 $ schema ,
146156 $ query ,
147- $ this ->resolverContext ,
157+ $ this ->contextFactory -> create () ,
148158 $ data ['variables ' ] ?? []
149159 );
150160 } catch (\Exception $ error ) {
0 commit comments