Skip to content

Fix infinite loop #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,13 @@ class UpdateUserEmailMutation extends Mutation
{
return [
'id' => ['required'],
'email' => ['required', 'email']
'email' => ['required', 'email'],
'password' => function($inputArguments, $mutationArguments) {
if ($inputArguments['id'] !== 1337) {
return ['required'];
}
return [];
}
];
}

Expand Down
208 changes: 0 additions & 208 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,6 @@ parameters:
count: 1
path: src/GraphQLServiceProvider.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:get\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/AliasArguments/AliasArguments.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:get\\(\\) has parameter \\$typedArgs with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/AliasArguments/AliasArguments.php

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

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:getAliasesInFields\\(\\) has parameter \\$parentType with no typehint specified\\.$#"
count: 1
path: src/Support/AliasArguments/AliasArguments.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\AliasArguments\\\\AliasArguments\\:\\:getAliasesInFields\\(\\) has parameter \\$prefix with no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -205,56 +191,6 @@ parameters:
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getRules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:resolveRules\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:resolveRules\\(\\) has parameter \\$rules with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:resolveRules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:inferRulesFromType\\(\\) has parameter \\$resolutionArguments with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:inferRulesFromType\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getInputTypeRules\\(\\) has parameter \\$resolutionArguments with no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getInputTypeRules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Support/Field.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Support\\\\Field\\:\\:getValidator\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -585,31 +521,6 @@ parameters:
count: 5
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php

-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:\\$attributes has no typehint specified\\.$#"
count: 1
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
count: 1
path: tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Database\\\\MutationValidationUniqueWithCustomRulesTests\\\\RuleObjectFail\\:\\:message\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -1660,71 +1571,6 @@ parameters:
count: 1
path: tests/Support/Objects/ExamplesQuery.php

-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:\\$attributes has no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) has parameter \\$context with no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutation\\:\\:resolve\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutation.php

-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:\\$attributes has no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\UpdateExampleMutationWithInputType\\:\\:resolve\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Support/Objects/UpdateExampleMutationWithInputType.php

-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Queries\\\\PostNonNullWithSelectFieldsAndModelQuery\\:\\:\\$attributes has no typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -2310,16 +2156,6 @@ parameters:
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithClosure\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithClosure\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithClosure\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
Expand All @@ -2330,31 +2166,6 @@ parameters:
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithClosure.php

-
message: "#^Property Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:\\$attributes has no typehint specified\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
count: 1
path: tests/Unit/MutationCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationCustomRulesTests\\\\RuleObject\\:\\:message\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -2375,25 +2186,6 @@ parameters:
count: 1
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:rules\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\MutationWithCustomRuleWithRuleObject\\:\\:resolve\\(\\) has parameter \\$root with no typehint specified\\.$#"
count: 1
path: tests/Unit/MutationValidationInWithCustomRulesTests/MutationWithCustomRuleWithRuleObject.php

-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Unit\\\\MutationValidationInWithCustomRulesTests\\\\RuleObjectFail\\:\\:message\\(\\) return type has no value type specified in iterable type array\\.$#"
Expand Down
1 change: 1 addition & 0 deletions src/GraphQLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function graphiql(Request $request, string $schema = null): View
protected function getRouteParameters(Request $request): array
{
if (Helpers::isLumen()) {
/** @var array<int,mixed> $route */
$route = $request->route();

return $route[2] ?? [];
Expand Down
62 changes: 51 additions & 11 deletions src/Support/AliasArguments/AliasArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,61 @@

class AliasArguments
{
public function get(array $typedArgs, array $arguments): array
/** @var array<string,mixed> */
private $queryArguments;
/** @var array<string,mixed> */
private $requestArguments;
/** @var int */
private $maxDepth;

/**
* @param array<string,mixed> $queryArguments
* @param array<string,mixed> $requestArguments
*/
public function __construct(array $queryArguments, array $requestArguments)
{
$pathsWithAlias = $this->getAliasesInFields($typedArgs, '');
$this->queryArguments = $queryArguments;
$this->requestArguments = $requestArguments;
$this->maxDepth = $this->getArrayDepth($this->requestArguments);
}

public function get(): array
{
$pathsWithAlias = $this->getAliasesInFields($this->queryArguments, '');

return (new ArrayKeyChange())->modify($arguments, $pathsWithAlias);
return (new ArrayKeyChange())->modify($this->requestArguments, $pathsWithAlias);
}

private function getAliasesInFields(array $fields, $prefix = '', $parentType = null): array
/**
* c/p from https://stackoverflow.com/questions/262891/is-there-a-way-to-find-out-how-deep-a-php-array-is/262944#262944.
*
* @param array<string,mixed> $array
* @return int
*/
protected function getArrayDepth(array $array): int
{
$maxDepth = 1;

foreach ($array as $value) {
if (is_array($value)) {
$depth = $this->getArrayDepth($value) + 1;

if ($depth > $maxDepth) {
$maxDepth = $depth;
}
}
}

return $maxDepth;
}

protected function getAliasesInFields(array $fields, $prefix = ''): array
{
// checks for traversal beyond the max depth
// this scenario occurs in types with recursive relations
if (substr_count($prefix, '.') > $this->maxDepth) {
return [];
}
$pathAndAlias = [];
foreach ($fields as $name => $arg) {
// $arg is either an array DSL notation or an InputObjectField
Expand Down Expand Up @@ -49,13 +95,7 @@ private function getAliasesInFields(array $fields, $prefix = '', $parentType = n
continue;
}

if ($parentType && $type->toString() === $parentType->toString()) {
// in case the field is a self reference we must not do
// a recursive call as it will never stop
continue;
}

$pathAndAlias = $pathAndAlias + $this->getAliasesInFields($type->getFields(), $newPrefix, $type);
$pathAndAlias = $pathAndAlias + $this->getAliasesInFields($type->getFields(), $newPrefix);
}

return $pathAndAlias;
Expand Down
Loading