Skip to content

Commit 95b7a0d

Browse files
authored
Merge pull request #579 from crissi/fix_infinite_loop
Fix infinite loop
2 parents 20349a5 + 1eb4a61 commit 95b7a0d

21 files changed

+1013
-373
lines changed

Readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,13 @@ class UpdateUserEmailMutation extends Mutation
446446
{
447447
return [
448448
'id' => ['required'],
449-
'email' => ['required', 'email']
449+
'email' => ['required', 'email'],
450+
'password' => function($inputArguments, $mutationArguments) {
451+
if ($inputArguments['id'] !== 1337) {
452+
return ['required'];
453+
}
454+
return [];
455+
}
450456
];
451457
}
452458

phpstan-baseline.neon

Lines changed: 0 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,6 @@ parameters:
110110
count: 1
111111
path: src/GraphQLServiceProvider.php
112112

113-
-
114-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:get\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
115-
count: 1
116-
path: src/Support/AliasArguments/AliasArguments.php
117-
118-
-
119-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:get\\(\\) has parameter \\$typedArgs with no value type specified in iterable type array\\.$#"
120-
count: 1
121-
path: src/Support/AliasArguments/AliasArguments.php
122113

123114
-
124115
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:get\\(\\) return type has no value type specified in iterable type array\\.$#"
@@ -130,11 +121,6 @@ parameters:
130121
count: 1
131122
path: src/Support/AliasArguments/AliasArguments.php
132123

133-
-
134-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:getAliasesInFields\\(\\) has parameter \\$parentType with no typehint specified\\.$#"
135-
count: 1
136-
path: src/Support/AliasArguments/AliasArguments.php
137-
138124
-
139125
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:getAliasesInFields\\(\\) has parameter \\$prefix with no typehint specified\\.$#"
140126
count: 1
@@ -205,56 +191,6 @@ parameters:
205191
count: 1
206192
path: src/Support/Field.php
207193

208-
-
209-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
210-
count: 1
211-
path: src/Support/Field.php
212-
213-
-
214-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
215-
count: 1
216-
path: src/Support/Field.php
217-
218-
-
219-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getRules\\(\\) return type has no value type specified in iterable type array\\.$#"
220-
count: 1
221-
path: src/Support/Field.php
222-
223-
-
224-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:resolveRules\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
225-
count: 1
226-
path: src/Support/Field.php
227-
228-
-
229-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:resolveRules\\(\\) has parameter \\$rules with no value type specified in iterable type array\\.$#"
230-
count: 1
231-
path: src/Support/Field.php
232-
233-
-
234-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:resolveRules\\(\\) return type has no value type specified in iterable type array\\.$#"
235-
count: 1
236-
path: src/Support/Field.php
237-
238-
-
239-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:inferRulesFromType\\(\\) has parameter \\$resolutionArguments with no value type specified in iterable type array\\.$#"
240-
count: 1
241-
path: src/Support/Field.php
242-
243-
-
244-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:inferRulesFromType\\(\\) return type has no value type specified in iterable type array\\.$#"
245-
count: 1
246-
path: src/Support/Field.php
247-
248-
-
249-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getInputTypeRules\\(\\) has parameter \\$resolutionArguments with no value type specified in iterable type array\\.$#"
250-
count: 1
251-
path: src/Support/Field.php
252-
253-
-
254-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getInputTypeRules\\(\\) return type has no value type specified in iterable type array\\.$#"
255-
count: 1
256-
path: src/Support/Field.php
257-
258194
-
259195
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getValidator\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
260196
count: 1
@@ -585,31 +521,6 @@ parameters:
585521
count: 5
586522
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
587523

588-
-
589-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:\\$attributes has no typehint specified\\.$#"
590-
count: 1
591-
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
592-
593-
-
594-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
595-
count: 1
596-
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
597-
598-
-
599-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
600-
count: 1
601-
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
602-
603-
-
604-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
605-
count: 1
606-
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
607-
608-
-
609-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
610-
count: 1
611-
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
612-
613524
-
614525
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\RuleObjectFail\\:\\:message\\(\\) return type has no value type specified in iterable type array\\.$#"
615526
count: 1
@@ -1660,71 +1571,6 @@ parameters:
16601571
count: 1
16611572
path: tests/Support/Objects/ExamplesQuery.php
16621573

1663-
-
1664-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:\\$attributes has no typehint specified\\.$#"
1665-
count: 1
1666-
path: tests/Support/Objects/UpdateExampleMutation.php
1667-
1668-
-
1669-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
1670-
count: 1
1671-
path: tests/Support/Objects/UpdateExampleMutation.php
1672-
1673-
-
1674-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
1675-
count: 1
1676-
path: tests/Support/Objects/UpdateExampleMutation.php
1677-
1678-
-
1679-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
1680-
count: 1
1681-
path: tests/Support/Objects/UpdateExampleMutation.php
1682-
1683-
-
1684-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) has parameter \\$context with no typehint specified\\.$#"
1685-
count: 1
1686-
path: tests/Support/Objects/UpdateExampleMutation.php
1687-
1688-
-
1689-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
1690-
count: 1
1691-
path: tests/Support/Objects/UpdateExampleMutation.php
1692-
1693-
-
1694-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) return type has no value type specified in iterable type array\\.$#"
1695-
count: 1
1696-
path: tests/Support/Objects/UpdateExampleMutation.php
1697-
1698-
-
1699-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:\\$attributes has no typehint specified\\.$#"
1700-
count: 1
1701-
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php
1702-
1703-
-
1704-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
1705-
count: 1
1706-
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php
1707-
1708-
-
1709-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
1710-
count: 1
1711-
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php
1712-
1713-
-
1714-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
1715-
count: 1
1716-
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php
1717-
1718-
-
1719-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
1720-
count: 1
1721-
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php
1722-
1723-
-
1724-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:resolve\\(\\) return type has no value type specified in iterable type array\\.$#"
1725-
count: 1
1726-
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php
1727-
17281574
-
17291575
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Queries\\\\PostNonNullWithSelectFieldsAndModelQuery\\:\\:\\$attributes has no typehint specified\\.$#"
17301576
count: 1
@@ -2310,16 +2156,6 @@ parameters:
23102156
count: 1
23112157
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php
23122158

2313-
-
2314-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithClosure\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
2315-
count: 1
2316-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php
2317-
2318-
-
2319-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithClosure\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
2320-
count: 1
2321-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php
2322-
23232159
-
23242160
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithClosure\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
23252161
count: 1
@@ -2330,31 +2166,6 @@ parameters:
23302166
count: 1
23312167
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php
23322168

2333-
-
2334-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:\\$attributes has no typehint specified\\.$#"
2335-
count: 1
2336-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2337-
2338-
-
2339-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
2340-
count: 1
2341-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2342-
2343-
-
2344-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
2345-
count: 1
2346-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2347-
2348-
-
2349-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
2350-
count: 1
2351-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2352-
2353-
-
2354-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
2355-
count: 1
2356-
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2357-
23582169
-
23592170
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\RuleObject\\:\\:message\\(\\) return type has no value type specified in iterable type array\\.$#"
23602171
count: 1
@@ -2375,25 +2186,6 @@ parameters:
23752186
count: 1
23762187
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
23772188

2378-
-
2379-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
2380-
count: 1
2381-
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2382-
2383-
-
2384-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
2385-
count: 1
2386-
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2387-
2388-
-
2389-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
2390-
count: 1
2391-
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
2392-
2393-
-
2394-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
2395-
count: 1
2396-
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php
23972189

23982190
-
23992191
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\RuleObjectFail\\:\\:message\\(\\) return type has no value type specified in iterable type array\\.$#"

src/GraphQLController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function graphiql(Request $request, string $schema = null): View
108108
protected function getRouteParameters(Request $request): array
109109
{
110110
if (Helpers::isLumen()) {
111+
/** @var array<int,mixed> $route */
111112
$route = $request->route();
112113

113114
return $route[2] ?? [];

src/Support/AliasArguments/AliasArguments.php

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,61 @@
1313

1414
class AliasArguments
1515
{
16-
public function get(array $typedArgs, array $arguments): array
16+
/** @var array<string,mixed> */
17+
private $queryArguments;
18+
/** @var array<string,mixed> */
19+
private $requestArguments;
20+
/** @var int */
21+
private $maxDepth;
22+
23+
/**
24+
* @param array<string,mixed> $queryArguments
25+
* @param array<string,mixed> $requestArguments
26+
*/
27+
public function __construct(array $queryArguments, array $requestArguments)
1728
{
18-
$pathsWithAlias = $this->getAliasesInFields($typedArgs, '');
29+
$this->queryArguments = $queryArguments;
30+
$this->requestArguments = $requestArguments;
31+
$this->maxDepth = $this->getArrayDepth($this->requestArguments);
32+
}
33+
34+
public function get(): array
35+
{
36+
$pathsWithAlias = $this->getAliasesInFields($this->queryArguments, '');
1937

20-
return (new ArrayKeyChange())->modify($arguments, $pathsWithAlias);
38+
return (new ArrayKeyChange())->modify($this->requestArguments, $pathsWithAlias);
2139
}
2240

23-
private function getAliasesInFields(array $fields, $prefix = '', $parentType = null): array
41+
/**
42+
* c/p from https://stackoverflow.com/questions/262891/is-there-a-way-to-find-out-how-deep-a-php-array-is/262944#262944.
43+
*
44+
* @param array<string,mixed> $array
45+
* @return int
46+
*/
47+
protected function getArrayDepth(array $array): int
2448
{
49+
$maxDepth = 1;
50+
51+
foreach ($array as $value) {
52+
if (is_array($value)) {
53+
$depth = $this->getArrayDepth($value) + 1;
54+
55+
if ($depth > $maxDepth) {
56+
$maxDepth = $depth;
57+
}
58+
}
59+
}
60+
61+
return $maxDepth;
62+
}
63+
64+
protected function getAliasesInFields(array $fields, $prefix = ''): array
65+
{
66+
// checks for traversal beyond the max depth
67+
// this scenario occurs in types with recursive relations
68+
if (substr_count($prefix, '.') > $this->maxDepth) {
69+
return [];
70+
}
2571
$pathAndAlias = [];
2672
foreach ($fields as $name => $arg) {
2773
// $arg is either an array DSL notation or an InputObjectField
@@ -49,13 +95,7 @@ private function getAliasesInFields(array $fields, $prefix = '', $parentType = n
4995
continue;
5096
}
5197

52-
if ($parentType && $type->toString() === $parentType->toString()) {
53-
// in case the field is a self reference we must not do
54-
// a recursive call as it will never stop
55-
continue;
56-
}
57-
58-
$pathAndAlias = $pathAndAlias + $this->getAliasesInFields($type->getFields(), $newPrefix, $type);
98+
$pathAndAlias = $pathAndAlias + $this->getAliasesInFields($type->getFields(), $newPrefix);
5999
}
60100

61101
return $pathAndAlias;

0 commit comments

Comments
 (0)