Skip to content
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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,17 @@ final class Data
* 'merged'?: bool,
* 'number'?: int,
* 'title'?: string,
* ...<int|string, mixed>,
* }>,
* ...<int|string, mixed>,
* },
* ...<int|string, mixed>,
* } $data
* @param list<array{
* 'code': string,
* 'debugMessage'?: string,
* 'message': string,
* ...<int|string, mixed>,
* }> $errors
*/
public function __construct(
Expand Down Expand Up @@ -763,22 +767,29 @@ final class Data
* 'node': array{
* 'id': int,
* 'name': string,
* ...<int|string, mixed>,
* },
* ...<int|string, mixed>,
* }>,
* ...<int|string, mixed>,
* },
* 'issues': list<array{
* 'id': int,
* 'name': string,
* ...<int|string, mixed>,
* }>,
* 'projects': list<array{
* 'id': string,
* 'name': string,
* ...<int|string, mixed>,
* }>,
* ...<int|string, mixed>,
* } $data
* @param list<array{
* 'code': string,
* 'debugMessage'?: string,
* 'message': string,
* ...<int|string, mixed>,
* }> $errors
*/
public function __construct(
Expand Down Expand Up @@ -859,7 +870,9 @@ final class Viewer
* 'project': null|array{
* 'id': string,
* 'name': string,
* ...<int|string, mixed>,
* },
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down Expand Up @@ -1075,6 +1088,7 @@ final class ProjectView
* 'description': null|string,
* 'name': string,
* 'state': null|string,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down Expand Up @@ -1108,6 +1122,7 @@ final class Project
* 'description': null|string,
* 'name': string,
* 'state': null|string,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"symfony/filesystem": "^8.0",
"symfony/finder": "^8.0",
"symfony/string": "^8.0",
"symfony/type-info": "^8.0",
"symfony/type-info": "^8.0.6",
"webmozart/assert": "^2.0",
"webonyx/graphql-php": "^15.24.0"
},
Expand Down
33 changes: 22 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/Generated/Fragment/PullRequestInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class PullRequestInfo
* 'merged': bool,
* 'number': int,
* 'title': string,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down
4 changes: 4 additions & 0 deletions examples/Generated/Query/Search/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ final class Data
* 'merged'?: bool,
* 'number'?: int,
* 'title'?: string,
* ...<int|string, mixed>,
* }>,
* ...<int|string, mixed>,
* },
* ...<int|string, mixed>,
* } $data
* @param list<array{
* 'code': string,
* 'debugMessage'?: string,
* 'message': string,
* ...<int|string, mixed>,
* }> $errors
*/
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ final class SearchResultItemConnection
* 'merged'?: bool,
* 'number'?: int,
* 'title'?: string,
* ...<int|string, mixed>,
* }>,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ final class Node
* 'merged'?: bool,
* 'number'?: int,
* 'title'?: string,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class AsIssue
* '__typename': 'Issue',
* 'number': int,
* 'title': string,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down
1 change: 1 addition & 0 deletions examples/Generated/Query/Search/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @param array{
* 'debugMessage'?: string,
* 'message': string,
* ...<int|string, mixed>,
* } $error
*/
public function __construct(array $error)
Expand Down
3 changes: 3 additions & 0 deletions examples/Generated/Query/Viewer/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ final class Data
* @param array{
* 'viewer': array{
* 'login': string,
* ...<int|string, mixed>,
* },
* ...<int|string, mixed>,
* } $data
* @param list<array{
* 'code': string,
* 'debugMessage'?: string,
* 'message': string,
* ...<int|string, mixed>,
* }> $errors
*/
public function __construct(
Expand Down
1 change: 1 addition & 0 deletions examples/Generated/Query/Viewer/Data/Viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class Viewer
/**
* @param array{
* 'login': string,
* ...<int|string, mixed>,
* } $data
*/
public function __construct(
Expand Down
1 change: 1 addition & 0 deletions examples/Generated/Query/Viewer/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @param array{
* 'debugMessage'?: string,
* 'message': string,
* ...<int|string, mixed>,
* } $error
*/
public function __construct(array $error)
Expand Down
2 changes: 1 addition & 1 deletion examples/GitHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function graphql(string $query, array $variables = [], ?string $operation

Assert::same(200, $response->getStatusCode(), 'GraphQL server responded with a %2$s status code.');

$data = json_decode((string) $response->getBody(), true, JSON_THROW_ON_ERROR);
$data = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);

Assert::isArray($data, 'GraphQL server did not return an array.');

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ protected function buildHooksShape(array $usedHooks) : Type
$shape[$name] = Type::object($this->config->hooks[$name]->class);
}

return Type::arrayShape($shape);
return Type::arrayShape($shape, sealed: false);
}
}
12 changes: 7 additions & 5 deletions src/Generator/DataClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ private function dumpLoadersShape(array $batchedHooks, array $plansByFqcn, CodeG
);
}

if ($entries === []) {
return 'array{}';
}
// Unsealed: nested classes receive `$this->loaders` from the Data class,
// which holds every batched hook in the operation, not just the subset a
// single nested class consumes. Extras are typed wide; HookLoader's
// covariant template params let any specific instantiation fit here.
$entries[] = sprintf('...<string, %s<array<int, mixed>, mixed>>', $hookLoader);

return sprintf("array{\n %s,\n}", implode(",\n ", $entries));
}
Expand Down Expand Up @@ -552,7 +554,7 @@ public function generate(DataClassPlan $plan, array $plansByFqcn = []) : string
if (isset($shape['__typename'])) {
// Use a StringLiteralType for the __typename
$shape['__typename'] = new StringLiteralType($possibleTypes[0]);
$payloadShape = SymfonyType::arrayShape($shape);
$payloadShape = SymfonyType::arrayShape($shape, sealed: false);
}
}

Expand Down Expand Up @@ -1119,7 +1121,7 @@ function () use ($plan, $parentType, $nodesType, $fields, $isData, $isMutationDa
'type' => SymfonyType::string(),
'optional' => true,
],
])), $generator->import(...)),
], sealed: false)), $generator->import(...)),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/ErrorClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function generate(ErrorClassPlan $plan) : string
'type' => Type::string(),
'optional' => true,
],
]), $generator->import(...))));
], sealed: false), $generator->import(...))));
yield 'public function __construct(array $error)';
yield '{';
yield $generator->indent(function () {
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/HookLoaderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function generate() : string
yield 'instance.';
yield '';
yield '@internal';
yield '@template TInput';
yield '@template TResult';
yield '@template-covariant TInput';
yield '@template-covariant TResult';
});
yield 'final class HookLoader';
yield '{';
Expand Down
2 changes: 1 addition & 1 deletion src/Planner/FieldCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function get(string $name) : SymfonyType

public function toArrayShape() : SymfonyType
{
return SymfonyType::arrayShape($this->fields);
return SymfonyType::arrayShape($this->fields, sealed: false);
}
}
6 changes: 3 additions & 3 deletions src/Planner/PayloadShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function merge(PayloadShape $other, bool $asOptional = false) : self
$existingType->getShape(),
$type->getShape(),
);
$this->replaceType($key, SymfonyType::arrayShape($mergedElements));
$this->replaceType($key, SymfonyType::arrayShape($mergedElements, sealed: false));

continue;
}
Expand All @@ -108,7 +108,7 @@ public function merge(PayloadShape $other, bool $asOptional = false) : self
$existingInner->getShape(),
$newInner->getShape(),
);
$this->replaceType($key, SymfonyType::list(SymfonyType::arrayShape($mergedElements)));
$this->replaceType($key, SymfonyType::list(SymfonyType::arrayShape($mergedElements, sealed: false)));
}
}

Expand All @@ -128,6 +128,6 @@ public function merge(PayloadShape $other, bool $asOptional = false) : self

public function toArrayShape() : SymfonyType
{
return SymfonyType::arrayShape($this->shape);
return SymfonyType::arrayShape($this->shape, sealed: false);
}
}
15 changes: 15 additions & 0 deletions src/Type/TypeDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ public static function dump(Type $type, ?callable $importer = null, int $indenta
$items[] = sprintf('%s: %s', $itemKey, self::dump($itemType, $importer, $indentation + 1));
}

if ( ! $type->isSealed()) {
$extraKey = $type->getExtraKeyType();
$extraValue = $type->getExtraValueType();

// Always emit `...<K, V>` rather than the bare `...` short form:
// PHPStan's `missingType.iterableValue` rule at level 6+ rejects
// the implicit `array-key, mixed` extras, treating them as a
// missing iterable value type.
$items[] = sprintf(
'...<%s, %s>',
self::dump($extraKey ?? Type::arrayKey(), $importer, $indentation + 1),
self::dump($extraValue ?? Type::mixed(), $importer, $indentation + 1),
);
}

if ($items === []) {
return 'array{}';
}
Expand Down
Loading
Loading