Skip to content

Commit 0c32d90

Browse files
authored
Ignore query parameters in non-GET requests
1 parent 5667177 commit 0c32d90

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## Unreleased
1111

12+
## v2.3.1
13+
14+
### Fixed
15+
16+
- Ignore query parameters in non-GET requests https://github.com/laragraph/utils/issues/26
17+
1218
## v2.3.0
1319

1420
### Added

src/RequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function bodyParams(Request $request): array
6363
return ['query' => $request->getContent()];
6464
}
6565

66-
$bodyParams = $request->input();
66+
$bodyParams = $request->post();
6767

6868
if (is_array($bodyParams) && count($bodyParams) > 0) {
6969
if (Arr::isAssoc($bodyParams)) {

tests/Unit/RequestParserTest.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ public function testPostWithBatchedRequest(): void
119119
self::assertSame($barQuery, $barParams->query);
120120
}
121121

122+
public function testPostWithBatchedRequestAndGetParams(): void
123+
{
124+
$fooQuery = /** @lang GraphQL */ '{ foo }';
125+
$barQuery = /** @lang GraphQL */ '{ bar }';
126+
$request = $this->makeRequest(
127+
'POST',
128+
[],
129+
[],
130+
['Content-Type' => 'application/json'],
131+
\Safe\json_encode([
132+
['query' => $fooQuery],
133+
['query' => $barQuery],
134+
]),
135+
'http://foo.bar/graphql?Operation=foo,bar'
136+
);
137+
$params = (new RequestParser())->parseRequest($request);
138+
139+
self::assertIsArray($params);
140+
[$fooParams, $barParams] = $params;
141+
self::assertSame($fooQuery, $fooParams->query);
142+
self::assertSame($barQuery, $barParams->query);
143+
}
144+
122145
public function testPostDefaultsToRegularForm(): void
123146
{
124147
$query = /** @lang GraphQL */ '{ foo }';
@@ -502,10 +525,10 @@ public function testMultipartFormWithNonJsonMap(): void
502525
* @param array<mixed> $headers
503526
* @param string|resource|null $content
504527
*/
505-
private function makeRequest(string $method, array $parameters = [], array $files = [], array $headers = [], $content = null): Request
528+
private function makeRequest(string $method, array $parameters = [], array $files = [], array $headers = [], $content = null, string $uri = 'http://foo.bar/graphql'): Request
506529
{
507530
$symfonyRequest = SymfonyRequest::create(
508-
'http://foo.bar/graphql',
531+
$uri,
509532
$method,
510533
$parameters,
511534
[],

0 commit comments

Comments
 (0)