You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
means that the source is now purged from results. If I then want to return the same Type instance later, I will get an error:
UnexpectedValueException: Object not found
/workspaces/graphqlite/src/PrefetchBuffer.php:90
This error only shows up in a nested prefetch context, specifically where an intermediate type is being prefetched, instances of that type are being shared, and it has a prefetched child field also.
In the test suite on this repo, this demonstrates the issue:
// tests/Integration/EndToEndTest.php// A NEW TEST TO DEMONSTRATE THE ISSUEpublicfunctiontestPrefetchingDeeplyNested(): void
{
$schema = $this->mainContainer->get(Schema::class);
assert($schemainstanceof Schema);
$schema->assertValid();
$queryString = ' query { companies { contact { name supervisor { name } } } }';
$result = GraphQL::executeQuery(
$schema,
$queryString,
null,
newContext(),
);
$this->assertSame([
'companies' => [
[
'contact' => [
'name' => 'Kate',
'supervisor' => [
'name' => 'The Boss',
],
],
],
[
'contact' => [
'name' => 'Kate',
'supervisor' => [
'name' => 'The Boss',
],
],
],
]
], $this->getSuccessResult($result));
}
Notably, it is the sharing of the $kate Type instance in the prefetchContacts method on CompanyType.php that causes the error:
There was 1 error:
1) TheCodingMachine\GraphQLite\Integration\EndToEndTest::testPrefetchingDeeplyNested
UnexpectedValueException: Object not found
/workspaces/graphqlite/src/PrefetchBuffer.php:90
/workspaces/graphqlite/src/Parameters/PrefetchDataParameter.php:60
/workspaces/graphqlite/vendor/webonyx/graphql-php/src/Executor/Promise/Adapter/SyncPromise.php:63
/workspaces/graphqlite/vendor/webonyx/graphql-php/src/Executor/Promise/Adapter/SyncPromise.php:50
/workspaces/graphqlite/vendor/webonyx/graphql-php/src/Executor/Promise/Adapter/SyncPromiseAdapter.php:147
/workspaces/graphqlite/vendor/webonyx/graphql-php/src/GraphQL.php:109
/workspaces/graphqlite/tests/Integration/EndToEndTest.php:2477
If I revert to using a new Type instance then the error goes away (see comment in above code). But this means I can't cache/reuse my Type instances in deeply nested prefetch scenarios.
Note if I don't fetch the child field supervisor (itself prefetched) then the error goes away. It is only apparent with nested prefetches.
Commenting out this line appears to fix the issue, but I'm unsure if this has repercussions elsewhere:
Is this expected behaviour? Am I meant to always return a new Type instance for each result, even if the result is identical and used elsewhere? This seems like a change if so?
The text was updated successfully, but these errors were encountered:
cdomigan
added a commit
to cdomigan/graphqlite
that referenced
this issue
Feb 17, 2025
Thank you for this wonderful library.
Until the change introduced by #702 by @sudevva I was able to "share" instances of Types in my prefetch logic.
The change to this line:
graphqlite/src/Parameters/PrefetchDataParameter.php
Line 62 in 37c06a9
means that the source is now purged from results. If I then want to return the same Type instance later, I will get an error:
This error only shows up in a nested prefetch context, specifically where an intermediate type is being prefetched, instances of that type are being shared, and it has a prefetched child field also.
In the test suite on this repo, this demonstrates the issue:
Notably, it is the sharing of the
$kate
Type instance in the prefetchContacts method on CompanyType.php that causes the error:If I revert to using a new Type instance then the error goes away (see comment in above code). But this means I can't cache/reuse my Type instances in deeply nested prefetch scenarios.
Note if I don't fetch the child field
supervisor
(itself prefetched) then the error goes away. It is only apparent with nested prefetches.Commenting out this line appears to fix the issue, but I'm unsure if this has repercussions elsewhere:
graphqlite/src/Parameters/PrefetchDataParameter.php
Line 62 in 37c06a9
Is this expected behaviour? Am I meant to always return a new Type instance for each result, even if the result is identical and used elsewhere? This seems like a change if so?
The text was updated successfully, but these errors were encountered: