Skip to content

Commit df06c28

Browse files
committed
change operation to OperationName in the parser
1 parent cfc05d1 commit df06c28

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/GraphQl/Action/EntrypointAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __invoke(Request $request): Response
9191
private function parseRequest(Request $request): array
9292
{
9393
$query = $request->query->get('query');
94-
$operation = $request->query->get('operation');
94+
$operation = $request->query->get('operationName');
9595
if ($variables = $request->query->get('variables', [])) {
9696
$variables = $this->decodeVariables($variables);
9797
}
@@ -132,8 +132,8 @@ private function parseData(?string $query, ?string $operation, array $variables,
132132
$variables = \is_array($data['variables']) ? $data['variables'] : $this->decodeVariables($data['variables']);
133133
}
134134

135-
if (isset($data['operation'])) {
136-
$operation = $data['operation'];
135+
if (isset($data['operationName'])) {
136+
$operation = $data['operationName'];
137137
}
138138

139139
return [$query, $operation, $variables];

tests/GraphQl/Action/EntrypointActionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testGetHtmlAction(): void
5858

5959
public function testGetAction(): void
6060
{
61-
$request = new Request(['query' => 'graphqlQuery', 'variables' => '["graphqlVariable"]', 'operation' => 'graphqlOperationName']);
61+
$request = new Request(['query' => 'graphqlQuery', 'variables' => '["graphqlVariable"]', 'operationName' => 'graphqlOperationName']);
6262
$request->setRequestFormat('json');
6363
$mockedEntrypoint = $this->getEntrypointAction();
6464

@@ -67,7 +67,7 @@ public function testGetAction(): void
6767

6868
public function testPostRawAction(): void
6969
{
70-
$request = new Request(['variables' => '["graphqlVariable"]', 'operation' => 'graphqlOperationName'], [], [], [], [], [], 'graphqlQuery');
70+
$request = new Request(['variables' => '["graphqlVariable"]', 'operationName' => 'graphqlOperationName'], [], [], [], [], [], 'graphqlQuery');
7171
$request->setFormat('graphql', 'application/graphql');
7272
$request->setMethod('POST');
7373
$request->headers->set('Content-Type', 'application/graphql');
@@ -78,7 +78,7 @@ public function testPostRawAction(): void
7878

7979
public function testPostJsonAction(): void
8080
{
81-
$request = new Request([], [], [], [], [], [], '{"query": "graphqlQuery", "variables": "[\"graphqlVariable\"]", "operation": "graphqlOperationName"}');
81+
$request = new Request([], [], [], [], [], [], '{"query": "graphqlQuery", "variables": "[\"graphqlVariable\"]", "operationName": "graphqlOperationName"}');
8282
$request->setMethod('POST');
8383
$request->headers->set('Content-Type', 'application/json');
8484
$mockedEntrypoint = $this->getEntrypointAction();
@@ -119,14 +119,14 @@ public function multipartRequestProvider(): array
119119

120120
return [
121121
'upload a single file' => [
122-
'{"query": "graphqlQuery", "variables": {"file": null}, "operation": "graphqlOperationName"}',
122+
'{"query": "graphqlQuery", "variables": {"file": null}, "operationName": "graphqlOperationName"}',
123123
'{"file": ["variables.file"]}',
124124
['file' => $file],
125125
['file' => $file],
126126
new JsonResponse(['GraphQL']),
127127
],
128128
'upload multiple files' => [
129-
'{"query": "graphqlQuery", "variables": {"files": [null, null, null]}, "operation": "graphqlOperationName"}',
129+
'{"query": "graphqlQuery", "variables": {"files": [null, null, null]}, "operationName": "graphqlOperationName"}',
130130
'{"0": ["variables.files.0"], "1": ["variables.files.1"], "2": ["variables.files.2"]}',
131131
[
132132
'0' => $file,
@@ -150,7 +150,7 @@ public function multipartRequestProvider(): array
150150
new Response('{"errors":[{"message":"GraphQL multipart request does not respect the specification.","extensions":{"category":"user","status":400}}]}'),
151151
],
152152
'upload without providing map' => [
153-
'{"query": "graphqlQuery", "variables": {"file": null}, "operation": "graphqlOperationName"}',
153+
'{"query": "graphqlQuery", "variables": {"file": null}, "operationName": "graphqlOperationName"}',
154154
null,
155155
['file' => $file],
156156
['file' => null],
@@ -164,28 +164,28 @@ public function multipartRequestProvider(): array
164164
new Response('{"errors":[{"message":"GraphQL data is not valid JSON.","extensions":{"category":"user","status":400}}]}'),
165165
],
166166
'upload with invalid map JSON' => [
167-
'{"query": "graphqlQuery", "variables": {"file": null}, "operation": "graphqlOperationName"}',
167+
'{"query": "graphqlQuery", "variables": {"file": null}, "operationName": "graphqlOperationName"}',
168168
'{invalid}',
169169
['file' => $file],
170170
['file' => null],
171171
new Response('{"errors":[{"message":"GraphQL multipart request map is not valid JSON.","extensions":{"category":"user","status":400}}]}'),
172172
],
173173
'upload with no file' => [
174-
'{"query": "graphqlQuery", "variables": {"file": null}, "operation": "graphqlOperationName"}',
174+
'{"query": "graphqlQuery", "variables": {"file": null}, "operationName": "graphqlOperationName"}',
175175
'{"file": ["file"]}',
176176
[],
177177
['file' => null],
178178
new Response('{"errors":[{"message":"GraphQL multipart request file has not been sent correctly.","extensions":{"category":"user","status":400}}]}'),
179179
],
180180
'upload with wrong map' => [
181-
'{"query": "graphqlQuery", "variables": {"file": null}, "operation": "graphqlOperationName"}',
181+
'{"query": "graphqlQuery", "variables": {"file": null}, "operationName": "graphqlOperationName"}',
182182
'{"file": ["file"]}',
183183
['file' => $file],
184184
['file' => null],
185185
new Response('{"errors":[{"message":"GraphQL multipart request path in map is invalid.","extensions":{"category":"user","status":400}}]}'),
186186
],
187187
'upload when variable path does not exist' => [
188-
'{"query": "graphqlQuery", "variables": {"file": null}, "operation": "graphqlOperationName"}',
188+
'{"query": "graphqlQuery", "variables": {"file": null}, "operationName": "graphqlOperationName"}',
189189
'{"file": ["variables.wrong"]}',
190190
['file' => $file],
191191
['file' => null],
@@ -217,7 +217,7 @@ public function testBadMethodAction(): void
217217

218218
public function testBadVariablesAction(): void
219219
{
220-
$request = new Request(['query' => 'graphqlQuery', 'variables' => 'graphqlVariable', 'operation' => 'graphqlOperationName']);
220+
$request = new Request(['query' => 'graphqlQuery', 'variables' => 'graphqlVariable', 'operationName' => 'graphqlOperationName']);
221221
$request->setRequestFormat('json');
222222
$mockedEntrypoint = $this->getEntrypointAction();
223223

0 commit comments

Comments
 (0)