Skip to content

Issue with union types in arrays #168

@moufmouf

Description

@moufmouf

There seems to be a bug with union types in arrays or on iterators:

    /**
     * @Query(name="getProduct")
     * @return (\TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Product|\TheCodingMachine\GraphQLite\Fixtures\Integration\Models\SpecialProduct)[]
     */
    public function getProducts2(): ArrayIterator
    {
        return new ArrayIterator([new SpecialProduct('Special box', 10.99), new SpecialProduct('Special box', 10.99)]);
    }

This causes this exception:

TheCodingMachine\GraphQLite\TypeMappingRuntimeException: Return type in TheCodingMachine\GraphQLite\Fixtures\Integration\Controllers\ProductController::getProducts2 is type-hinted to array. Please provide an additional @return in the PHPDoc block to further specify the type of the array. For instance: @return string[]

/home/david/projects/sandbox/graphql-controllers/src/TypeMappingRuntimeException.php:123
/home/david/projects/sandbox/graphql-controllers/src/Mappers/Parameters/TypeHandler.php:100
/home/david/projects/sandbox/graphql-controllers/src/FieldsBuilder.php:297
/home/david/projects/sandbox/graphql-controllers/src/FieldsBuilder.php:88
/home/david/projects/sandbox/graphql-controllers/src/AggregateControllerQueryProvider.php:43
/home/david/projects/sandbox/graphql-controllers/src/GlobControllerQueryProvider.php:121
/home/david/projects/sandbox/graphql-controllers/src/AggregateQueryProvider.php:34
/home/david/projects/sandbox/graphql-controllers/src/AggregateQueryProvider.php:35
/home/david/projects/sandbox/graphql-controllers/src/Schema.php:36
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Definition/FieldDefinition.php:90
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Definition/ObjectType.php:151
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Utils/TypeInfo.php:180
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:213
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:199
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/SchemaValidationContext.php:244
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:517
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:469
/home/david/projects/sandbox/graphql-controllers/tests/SchemaFactoryTest.php:144
/home/david/projects/sandbox/graphql-controllers/tests/SchemaFactoryTest.php:50

Caused by
TheCodingMachine\GraphQLite\TypeMappingRuntimeException: Don't know how to handle type (\TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Product|\TheCodingMachine\GraphQLite\Fixtures\Integration\Models\SpecialProduct)[]

/home/david/projects/sandbox/graphql-controllers/src/TypeMappingRuntimeException.php:28
/home/david/projects/sandbox/graphql-controllers/src/Mappers/Parameters/TypeHandler.php:361
/home/david/projects/sandbox/graphql-controllers/src/Mappers/Parameters/TypeHandler.php:238
/home/david/projects/sandbox/graphql-controllers/src/Mappers/Parameters/TypeHandler.php:325
/home/david/projects/sandbox/graphql-controllers/src/Mappers/Parameters/TypeHandler.php:212
/home/david/projects/sandbox/graphql-controllers/src/Mappers/Parameters/TypeHandler.php:98
/home/david/projects/sandbox/graphql-controllers/src/FieldsBuilder.php:297
/home/david/projects/sandbox/graphql-controllers/src/FieldsBuilder.php:88
/home/david/projects/sandbox/graphql-controllers/src/AggregateControllerQueryProvider.php:43
/home/david/projects/sandbox/graphql-controllers/src/GlobControllerQueryProvider.php:121
/home/david/projects/sandbox/graphql-controllers/src/AggregateQueryProvider.php:34
/home/david/projects/sandbox/graphql-controllers/src/AggregateQueryProvider.php:35
/home/david/projects/sandbox/graphql-controllers/src/Schema.php:36
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Definition/FieldDefinition.php:90
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Definition/ObjectType.php:151
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Utils/TypeInfo.php:180
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:213
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:199
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/SchemaValidationContext.php:244
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:517
/home/david/projects/sandbox/graphql-controllers/vendor/webonyx/graphql-php/src/Type/Schema.php:469
/home/david/projects/sandbox/graphql-controllers/tests/SchemaFactoryTest.php:144
/home/david/projects/sandbox/graphql-controllers/tests/SchemaFactoryTest.php:50

Related to #167

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions