Allow null results in graphql entity results

Created on 3 April 2025, 5 days ago

Problem/Motivation

After creating a view that uses contextual filters, which shows no results when certain conditions aren't meet, I get this error:

For error #0: TypeError: Drupal\Core\Cache\CacheableMetadata::createFromRenderArray(): Argument #1 ($build) must be of type array, null given, called in /var/www/html/web/modules/contrib/graphql_compose/modules/graphql_compose_views/src/Plugin/GraphQL/DataProducer/ViewsEntityResults.php on line 47

It looks like it does not usually happen. I far as I have debugged, it happened in a view with contextual filters that have empty default arguments.

Steps to reproduce

- Use Graphql compose latest version
- Enable graphql views.
- Create a view with a Graphql display
- Add a contextual filter , setting that if no contextual filters are available, provide a default value that may return an empty value.

When the contextual filter returns an empty value, the error appears.

Proposed resolution

The problem comes from this line.

The method CacheableMetadata::createFromRenderArray expects an array, but $view->render may return null.

So the solution would be, when results come null in GraphqlEntityResults DataProducer, pass an empty array to CacheableMetadata::createFromRenderArray

πŸ› Bug report
Status

Active

Version

2.4

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain omarlopesino

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024