ApiPltaform – GraphQL Issue – Null value in DatetimeType field throw "Resource "DateTime" not found"

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": "ApiPlatformCoreMetadataResourceFactoryAnnotationResourceFilterMetadataFactory::handleNotFound(null, 'DateTime')"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/OperationResourceMetadataFactory.php",
          "line": 57,
          "call": "ApiPlatformCoreMetadataResourceFactoryAnnotationResourceFilterMetadataFactory::create('DateTime')"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/FormatsResourceMetadataFactory.php",
          "line": 53,
          "call": "ApiPlatformCoreMetadataResourceFactoryOperationResourceMetadataFactory::create('DateTime')"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/CachedResourceMetadataFactory.php",
          "line": 47,
          "call": "ApiPlatformCoreMetadataResourceFactoryFormatsResourceMetadataFactory::create('DateTime')"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/Cache/CachedTrait.php",
          "line": 44,
          "call": "ApiPlatformCoreMetadataResourceFactoryCachedResourceMetadataFactory::ApiPlatformCoreMetadataResourceFactory{closure}()"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/Metadata/Resource/Factory/CachedResourceMetadataFactory.php",
          "line": 48,
          "call": "ApiPlatformCoreMetadataResourceFactoryCachedResourceMetadataFactory::getCached('resource_metadata_8cf10d2341ed01492506085688270c1e', instance of Closure)"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/GraphQl/Resolver/Stage/ReadStage.php",
          "line": 60,
          "call": "ApiPlatformCoreMetadataResourceFactoryCachedResourceMetadataFactory::create('DateTime')"
        },
        {
          "file": "/var/www/app/vendor/api-platform/core/src/GraphQl/Resolver/Factory/ItemResolverFactory.php",
          "line": 70,
          "call": "ApiPlatformCoreGraphQlResolverStageReadStage::__invoke('DateTime', 'AppEntityUser', 'item_query', array(5))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 630,
          "call": "ApiPlatformCoreGraphQlResolverFactoryItemResolverFactory::ApiPlatformCoreGraphQlResolverFactory{closure}(array(4), array(0), null, instance of GraphQLTypeDefinitionResolveInfo)"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 557,
          "call": "GraphQLExecutorReferenceExecutor::resolveFieldValueOrError(instance of GraphQLTypeDefinitionFieldDefinition, instance of GraphQLLanguageASTFieldNode, instance of Closure, array(4), instance of GraphQLTypeDefinitionResolveInfo)"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 1200,
          "call": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::completeObjectValue(GraphQLType: User, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(4), array(4))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 662,
          "call": "GraphQLExecutorReferenceExecutor::completeValue(GraphQLType: User, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(4), array(4))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 564,
          "call": "GraphQLExecutorReferenceExecutor::completeValueCatchingError(GraphQLType: User, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(4), array(4))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 1200,
          "call": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::completeObjectValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(3), array(2))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 662,
          "call": "GraphQLExecutorReferenceExecutor::completeValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(3), array(2))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 895,
          "call": "GraphQLExecutorReferenceExecutor::completeValueCatchingError(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(3), array(2))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 764,
          "call": "GraphQLExecutorReferenceExecutor::completeListValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(2), array(2))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 662,
          "call": "GraphQLExecutorReferenceExecutor::completeValue(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(2), array(2))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 564,
          "call": "GraphQLExecutorReferenceExecutor::completeValueCatchingError(GraphQLType: UserEdge, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(2), array(2))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 1200,
          "call": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::completeObjectValue(GraphQLType: UserConnection, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(1), array(3))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 662,
          "call": "GraphQLExecutorReferenceExecutor::completeValue(GraphQLType: UserConnection, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(1), array(3))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 564,
          "call": "GraphQLExecutorReferenceExecutor::completeValueCatchingError(GraphQLType: UserConnection, instance of ArrayObject(1), instance of GraphQLTypeDefinitionResolveInfo, array(1), array(3))"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php",
          "line": 1200,
          "call": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::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": "GraphQLExecutorReferenceExecutor::executeOperation(instance of GraphQLLanguageASTOperationDefinitionNode, null)"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/Executor/Executor.php",
          "line": 155,
          "call": "GraphQLExecutorReferenceExecutor::doExecute()"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 162,
          "call": "GraphQLExecutorExecutor::promiseToExecute(instance of GraphQLExecutorPromiseAdapterSyncPromiseAdapter, instance of GraphQLTypeSchema, instance of GraphQLLanguageASTDocumentNode, null, null, array(0), null, null)"
        },
        {
          "file": "/var/www/app/vendor/webonyx/graphql-php/src/GraphQL.php",
          "line": 94,
          "call": "GraphQLGraphQL::promiseToExecute(instance of GraphQLExecutorPromiseAdapterSyncPromiseAdapter, instance of GraphQLTypeSchema, 'query {n  users (first: 2) {n    edges {n      node {n        username,n        sampleNullableDaten      }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": "GraphQLGraphQL::executeQuery(instance of GraphQLTypeSchema, 'query {n  users (first: 2) {n    edges {n      node {n        username,n        sampleNullableDaten      }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": "ApiPlatformCoreGraphQlExecutor::executeQuery(instance of GraphQLTypeSchema, 'query {n  users (first: 2) {n    edges {n      node {n        username,n        sampleNullableDaten      }n    }n  }n}', null, null, array(0), null)"
        },
        {
          "file": "/var/www/app/vendor/symfony/http-kernel/HttpKernel.php",
          "line": 158,
          "call": "ApiPlatformCoreGraphQlActionEntrypointAction::__invoke(instance of SymfonyComponentHttpFoundationRequest)"
        },
        {
          "file": "/var/www/app/vendor/symfony/http-kernel/HttpKernel.php",
          "line": 80,
          "call": "SymfonyComponentHttpKernelHttpKernel::handleRaw(instance of SymfonyComponentHttpFoundationRequest, 1)"
        },
        {
          "file": "/var/www/app/vendor/symfony/http-kernel/Kernel.php",
          "line": 201,
          "call": "SymfonyComponentHttpKernelHttpKernel::handle(instance of SymfonyComponentHttpFoundationRequest, 1, true)"
        },
        {
          "file": "/var/www/app/public/index.php",
          "line": 25,
          "call": "SymfonyComponentHttpKernelKernel::handle(instance of SymfonyComponentHttpFoundationRequest)"
        }
      ]
    }
  ],
  "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

Source: Symfony4 Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *