-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Description
When submitting a GraphQL mutation that includes a Matrix field, the graphql-authentication plugin throws an internal server error due to a type mismatch in the RestrictionService::_ensureValidEntry()
method.
Error
TypeError: jamesedmonston\graphqlauthentication\services\RestrictionService::_ensureValidEntry(): Argument #1 ($id) must be of type int, null given
Context
This occurs when the GraphQL mutation includes unsaved Matrix block data. Matrix blocks in Craft are instances of craft\elements\Entry
, but they do not yet have IDs during mutation submission. The plugin attempts to validate these elements as if they were saved entries, which causes the fatal error when it passes a null value as the entry ID.
Where
The error is triggered in:
jamesedmonston\graphqlauthentication\services\RestrictionService::restrictMutationFieldsForElement
Why This Is a Problem
Matrix blocks are valid content elements in CraftCMS GraphQL mutations, and it is expected behavior that they do not have IDs prior to being saved. The plugin's current handling of these blocks incorrectly assumes all craft\elements\Entry objects are persisted and have valid IDs. This blocks legitimate GraphQL mutations and breaks compatibility with common content modeling patterns in Craft.
Expected Behavior
Matrix blocks should be safely handled during validation, without triggering a type error due to missing IDs.
Suggested Fix (or something similar)
Add a check before calling _ensureValidEntry() to ensure that $e->id is not null:
} elseif ($e instanceof Entry) { if (!$e->id) { Craft::warning('Skipping Entry with null ID — likely a Matrix block.', __METHOD__); continue; } $this->_ensureValidEntry($e->id, $element->siteId); }
Setup
Craft edition & version | Craft Pro 5.6.17
GraphQL Authentication | 3.0.0-RC5
PHP version | 8.3.9