File entity load error

Created on 28 May 2024, 7 months ago

Problem/Motivation

When running a simple graphql query on File entities, it results in an error. Below is the graphql query followed by the error

query MyQuery {
  entityById(entityType: FILE, id: "1") {
    label
    id
  }
}
ArgumentCountError: file() expects at least 1 argument, 0 given in file() (line 406 of /app/vendor/webonyx/graphql-php/src/Type/Schema.php)
#0 /app/vendor/webonyx/graphql-php/src/Type/Schema.php(406): file()
#1 /app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php(946): GraphQL\Type\Schema::resolveType('File')
#2 /app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php(789): GraphQL\Executor\ReferenceExecutor->completeAbstractValue(Object(GraphQL\Type\Definition\InterfaceType), Object(ArrayObject), Object(GraphQL\Type\Definition\ResolveInfo), Array, Object(Drupal\file\Entity\File))
#3 /app/vendor/webonyx/graphql-php/src/Executor/ReferenceExecutor.php(651): GraphQL\Executor\ReferenceExecutor->completeValue(Object(GraphQL\Type\Definition\InterfaceType), Object(ArrayObject), Object(GraphQL\Type\Definition\ResolveInfo), Array, Object(Drupal\file\Entity\File))
#4 /app/vendor/webonyx/graphql-php/src/Executor/Promise/Adapter/SyncPromise.php(148): GraphQL\Executor\ReferenceExecutor->GraphQL\Executor\{closure}(Object(Drupal\file\Entity\File))
#5 /app/vendor/webonyx/graphql-php/src/Executor/Promise/Adapter/SyncPromise.php(53): GraphQL\Executor\Promise\Adapter\SyncPromise->GraphQL\Executor\Promise\Adapter\{closure}()

I also tried with referenced entities and I get the same above error.

query MyQuery {
  entityQuery(entityType: NODE) {
    items {
      ... on NodeArticle {
        id
        title
        referencedEntities {
          id
        }
      }
    }
  }
}

Steps to reproduce

- On a fresh Drupal 9 install, add an image field (Image) to the Article content type
- Enable the following extensions in the Core Schema Server
- Entity Query Extension
- Image
- Reverse Entity Reference
- Enable the following entity types, file, node and node_type
- Run the above provided graphql queries
- Notice the error in the error logs

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇲🇺Mauritius whiz11

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @whiz11
  • 🇨🇭Switzerland dulnan

    I debugged this and it turns out it is (or more was) a bug in webonyx/graphql-php: https://github.com/webonyx/graphql-php/pull/1194
    It happens because it tries to resolve our "File" type. This code:

    elseif (is_callable($typeCandidate) {
    

    Because is_callable("File") will return true, it then later on calls file(), which leads to the error here.

    This seems to have been fixed already for quite some time, but the Drupal graphql Module still uses v14 of the library. There seems to be work going on to update to v15. Until then, I'll have to see what I can do to prevent this from happening.

  • Status changed to Fixed 5 months ago
  • 🇨🇭Switzerland dulnan

    I found a workaround to prevent this from happening, until graphql updates to v15.

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇷🇸Serbia thenchev

    The issue remains unresolved until we update the version of graphql-php. I am uploading a patch here that can be applied to graphql-php (not this module). The linked issue at #3 contains the changes along with additional test coverage, but the patch no longer applies.

Production build 0.71.5 2024