diff --git a/src/TypeMapper.php b/src/TypeMapper.php index 95c8567..2184508 100644 --- a/src/TypeMapper.php +++ b/src/TypeMapper.php @@ -93,7 +93,7 @@ public function mapGraphQLTypeToPHPType(Type $type, ?bool $nullable = null, bool } if ($type instanceof ListOfType) { - return SymfonyType::list($this->mapGraphQLTypeToPHPType($type->getWrappedType(), $builtInOnly)); + return SymfonyType::list($this->mapGraphQLTypeToPHPType($type->getWrappedType(), null, $builtInOnly)); } if ($type instanceof ScalarType) { diff --git a/tests/ListScalar/Generated/Query/Test/Data.php b/tests/ListScalar/Generated/Query/Test/Data.php new file mode 100644 index 0000000..a4f0114 --- /dev/null +++ b/tests/ListScalar/Generated/Query/Test/Data.php @@ -0,0 +1,50 @@ + + */ + public array $supportedCurrencies { + get => $this->supportedCurrencies ??= array_map(fn($item) => new Currency($item), $this->data['supportedCurrencies']); + } + + public Wallet $wallet { + get => $this->wallet ??= new Wallet($this->data['wallet']); + } + + /** + * @var list + */ + public readonly array $errors; + + /** + * @param array{ + * 'supportedCurrencies': list, + * 'wallet': array{ + * 'currencies': list, + * 'name': string, + * }, + * } $data + * @param list $errors + */ + public function __construct( + private readonly array $data, + array $errors, + ) { + $this->errors = array_map(fn(array $error) => new Error($error), $errors); + } +} diff --git a/tests/ListScalar/Generated/Query/Test/Data/Wallet.php b/tests/ListScalar/Generated/Query/Test/Data/Wallet.php new file mode 100644 index 0000000..ad02de8 --- /dev/null +++ b/tests/ListScalar/Generated/Query/Test/Data/Wallet.php @@ -0,0 +1,33 @@ + + */ + public array $currencies { + get => $this->currencies ??= array_map(fn($item) => new Currency($item), $this->data['currencies']); + } + + public string $name { + get => $this->name ??= $this->data['name']; + } + + /** + * @param array{ + * 'currencies': list, + * 'name': string, + * } $data + */ + public function __construct( + private readonly array $data, + ) {} +} diff --git a/tests/ListScalar/Generated/Query/Test/Error.php b/tests/ListScalar/Generated/Query/Test/Error.php new file mode 100644 index 0000000..6e0a888 --- /dev/null +++ b/tests/ListScalar/Generated/Query/Test/Error.php @@ -0,0 +1,23 @@ +message = $error['debugMessage'] ?? $error['message']; + } +} diff --git a/tests/ListScalar/Generated/Query/Test/TestQuery.php b/tests/ListScalar/Generated/Query/Test/TestQuery.php new file mode 100644 index 0000000..c7053b3 --- /dev/null +++ b/tests/ListScalar/Generated/Query/Test/TestQuery.php @@ -0,0 +1,42 @@ +client->graphql( + self::OPERATION_DEFINITION, + [ + ], + self::OPERATION_NAME, + ); + + return new Data( + $data['data'] ?? [], // @phpstan-ignore argument.type + $data['errors'] ?? [] // @phpstan-ignore argument.type + ); + } +} diff --git a/tests/ListScalar/ListScalarTest.php b/tests/ListScalar/ListScalarTest.php new file mode 100644 index 0000000..68477f3 --- /dev/null +++ b/tests/ListScalar/ListScalarTest.php @@ -0,0 +1,61 @@ +withScalar('Currency', Type::string(), Type::object(Currency::class)); + } + + public function testGenerate() : void + { + $this->assertActualMatchesExpected(); + } + + public function testQueryWithListOfScalars() : void + { + $result = new TestQuery($this->getClient([ + 'data' => [ + 'supportedCurrencies' => ['EUR', 'USD', 'GBP'], + 'wallet' => [ + 'name' => 'My Wallet', + 'currencies' => ['EUR', 'USD'], + ], + ], + ]))->execute(); + + // Verify the list of currencies is correctly converted to Currency objects + self::assertCount(3, $result->supportedCurrencies); + self::assertSame('EUR', $result->supportedCurrencies[0]->code); + self::assertSame('USD', $result->supportedCurrencies[1]->code); + self::assertSame('GBP', $result->supportedCurrencies[2]->code); + + // Verify nested list of currencies + self::assertSame('My Wallet', $result->wallet->name); + self::assertCount(2, $result->wallet->currencies); + self::assertSame('EUR', $result->wallet->currencies[0]->code); + self::assertSame('USD', $result->wallet->currencies[1]->code); + } +} diff --git a/tests/ListScalar/Schema.graphql b/tests/ListScalar/Schema.graphql new file mode 100644 index 0000000..461b2e7 --- /dev/null +++ b/tests/ListScalar/Schema.graphql @@ -0,0 +1,11 @@ +scalar Currency + +type Query { + supportedCurrencies: [Currency!]! + wallet: Wallet! +} + +type Wallet { + name: String! + currencies: [Currency!]! +} diff --git a/tests/ListScalar/Test.graphql b/tests/ListScalar/Test.graphql new file mode 100644 index 0000000..a18d229 --- /dev/null +++ b/tests/ListScalar/Test.graphql @@ -0,0 +1,7 @@ +query Test { + supportedCurrencies + wallet { + name + currencies + } +} diff --git a/tests/ListScalar/ValueObjects/Currency.php b/tests/ListScalar/ValueObjects/Currency.php new file mode 100644 index 0000000..7e59f9c --- /dev/null +++ b/tests/ListScalar/ValueObjects/Currency.php @@ -0,0 +1,33 @@ +code; + } + + #[Override] + public function __toString() : string + { + return $this->code; + } +}