API Platform version(s) affected: v2.5.7 (symfony v4.4.13 on PHP 7.4)
Description
I have an Entity with a field typed with a custom type.
It works great if the field isn't null.
If there is an item with a null value, it throw a "Resource \"DateTime\" not found
I created a custom DateTimeType, I have some item with null values on field typed by that custom type.
If there is a null value in the result I get such error :
{"errors": [ {"debugMessage": "Resource \"DateTime\" not found.","message": "Internal server error","extensions": {"category": "internal" },"locations": [ {"line": 6,"column": 9 } ],"path": ["users","edges", 1,"node","sampleNullableDate" ],"trace": [ {"file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/AnnotationResourceFilterMetadataFactory.php","line": 55,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\AnnotationResourceFilterMetadataFactory::handleNotFound(null, 'DateTime')" }, {"file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/OperationResourceMetadataFactory.php","line": 57,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\AnnotationResourceFilterMetadataFactory::create('DateTime')" }, {"file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/FormatsResourceMetadataFactory.php","line": 53,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\OperationResourceMetadataFactory::create('DateTime')" }, {"file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/CachedResourceMetadataFactory.php","line": 47,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\FormatsResourceMetadataFactory::create('DateTime')" }, {"file": "/var/www/app/vendor/api-platform/core/src/Cache/CachedTrait.php","line": 44,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\CachedResourceMetadataFactory::ApiPlatform\\Core\\Metadata\\Resource\\Factory\\{closure}()" }, {"file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/CachedResourceMetadataFactory.php","line": 48,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\CachedResourceMetadataFactory::getCached('resource_metadata_8cf10d2341ed01492506085688270c1e', instance of Closure)" }, {"file": "/var/www/app/vendor/api-platform/core/src/GraphQl/Resolver/Stage/ReadStage.php","line": 60,"call": "ApiPlatform\\Core\\Metadata\\Resource\\Factory\\CachedResourceMetadataFactory::create('DateTime')" }, {"file": "/var/www/app/vendor/api-platform/core/src/GraphQl/Resolver/Factory/ItemResolverFactory.php","line": 70,"call": "ApiPlatform\\Core\\GraphQl\\Resolver\\Stage\\ReadStage::__invoke('DateTime', 'App\\Entity\\User', 'item_query', array(5))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 630,"call": "ApiPlatform\\Core\\GraphQl\\Resolver\\Factory\\ItemResolverFactory::ApiPlatform\\Core\\GraphQl\\Resolver\\Factory\\{closure}(array(4), array(0), null, instance of GraphQL\\Type\\Definition\\ResolveInfo)" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 557,"call": "GraphQL\\Executor\\ReferenceExecutor::resolveFieldValueOrError(instance of GraphQL\\Type\\Definition\\FieldDefinition, instance of GraphQL\\Language\\AST\\FieldNode, instance of Closure, array(4), instance of GraphQL\\Type\\Definition\\ResolveInfo)" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1200,"call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: User, array(4), instance of ArrayObject(1), array(5))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1147,"call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: User, array(4), array(4), instance of ArrayObject(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1106,"call": "GraphQL\\Executor\\ReferenceExecutor::collectAndExecuteSubfields(GraphQLType: User, instance of ArrayObject(1), array(4), array(4))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 796,"call": "GraphQL\\Executor\\ReferenceExecutor::completeObjectValue(GraphQLType: User, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(4), array(4))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 662,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValue(GraphQLType: User, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(4), array(4))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 564,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValueCatchingError(GraphQLType: User, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(4), array(4))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1200,"call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: UserEdge, array(2), instance of ArrayObject(1), array(4))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1147,"call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: UserEdge, array(2), array(3), instance of ArrayObject(1))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1106,"call": "GraphQL\\Executor\\ReferenceExecutor::collectAndExecuteSubfields(GraphQLType: UserEdge, instance of ArrayObject(1), array(3), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 796,"call": "GraphQL\\Executor\\ReferenceExecutor::completeObjectValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(3), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 662,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(3), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 895,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValueCatchingError(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(3), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 764,"call": "GraphQL\\Executor\\ReferenceExecutor::completeListValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(2), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 662,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(2), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 564,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValueCatchingError(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(2), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1200,"call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: UserConnection, array(3), instance of ArrayObject(1), array(2))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1147,"call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: UserConnection, array(3), array(1), instance of ArrayObject(1))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1106,"call": "GraphQL\\Executor\\ReferenceExecutor::collectAndExecuteSubfields(GraphQLType: UserConnection, instance of ArrayObject(1), array(1), array(3))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 796,"call": "GraphQL\\Executor\\ReferenceExecutor::completeObjectValue(GraphQLType: UserConnection, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(1), array(3))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 662,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValue(GraphQLType: UserConnection, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(1), array(3))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 564,"call": "GraphQL\\Executor\\ReferenceExecutor::completeValueCatchingError(GraphQLType: UserConnection, instance of ArrayObject(1), instance of GraphQL\\Type\\Definition\\ResolveInfo, array(1), array(3))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 1200,"call": "GraphQL\\Executor\\ReferenceExecutor::resolveField(GraphQLType: Query, null, instance of ArrayObject(1), array(1))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 258,"call": "GraphQL\\Executor\\ReferenceExecutor::executeFields(GraphQLType: Query, null, array(0), instance of ArrayObject(1))" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php","line": 209,"call": "GraphQL\\Executor\\ReferenceExecutor::executeOperation(instance of GraphQL\\Language\\AST\\OperationDefinitionNode, null)" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/Executor.php","line": 155,"call": "GraphQL\\Executor\\ReferenceExecutor::doExecute()" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/GraphQL.php","line": 162,"call": "GraphQL\\Executor\\Executor::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, instance of GraphQL\\Language\\AST\\DocumentNode, null, null, array(0), null, null)" }, {"file": "/var/www/app/vendor/webonyx/graphql-php/src/GraphQL.php","line": 94,"call": "GraphQL\\GraphQL::promiseToExecute(instance of GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter, instance of GraphQL\\Type\\Schema, 'query {\n users (first: 2) {\n edges {\n node {\n username,\n sampleNullableDate\n }\n }\n }\n}', null, null, array(0), null, null, null)" }, {"file": "/var/www/app/vendor/api-platform/core/src/GraphQl/Executor.php","line": 34,"call": "GraphQL\\GraphQL::executeQuery(instance of GraphQL\\Type\\Schema, 'query {\n users (first: 2) {\n edges {\n node {\n username,\n sampleNullableDate\n }\n }\n }\n}', null, null, array(0), null, null, null)" }, {"file": "/var/www/app/vendor/api-platform/core/src/GraphQl/Action/EntrypointAction.php","line": 78,"call": "ApiPlatform\\Core\\GraphQl\\Executor::executeQuery(instance of GraphQL\\Type\\Schema, 'query {\n users (first: 2) {\n edges {\n node {\n username,\n sampleNullableDate\n }\n }\n }\n}', null, null, array(0), null)" }, {"file": "/var/www/app/vendor/symfony/http-kernel/HttpKernel.php","line": 158,"call": "ApiPlatform\\Core\\GraphQl\\Action\\EntrypointAction::__invoke(instance of Symfony\\Component\\HttpFoundation\\Request)" }, {"file": "/var/www/app/vendor/symfony/http-kernel/HttpKernel.php","line": 80,"call": "Symfony\\Component\\HttpKernel\\HttpKernel::handleRaw(instance of Symfony\\Component\\HttpFoundation\\Request, 1)" }, {"file": "/var/www/app/vendor/symfony/http-kernel/Kernel.php","line": 201,"call": "Symfony\\Component\\HttpKernel\\HttpKernel::handle(instance of Symfony\\Component\\HttpFoundation\\Request, 1, true)" }, {"file": "/var/www/app/public/index.php","line": 25,"call": "Symfony\\Component\\HttpKernel\\Kernel::handle(instance of Symfony\\Component\\HttpFoundation\\Request)" } ] } ],"data": {"users": {"edges": [ {"node": {"username": "user OK with date not null","sampleNullableDate": "07-09-2020 09:09:03" } }, {"node": {"username": "user NOK with null date","sampleNullableDate": null } } ] } }}
How to reproduce
Following that documentation: https://api-platform.com/docs/core/graphql/#custom-types
And this one : https://api-platform.com/docs/core/graphql/#custom-types
And having at least a field with a null value.
Here is a test project to reproduce : https://github.com/bastoune/api-platform-test-project/tree/issue/DateTimeType