Skip to content

Automatic Persisted Queries work with hybrid cache mode#2727

Merged
spawnia merged 2 commits into
nuwave:masterfrom
Kauto:automatic_persisted_queries_work_with_hybrid_mode
Dec 5, 2025
Merged

Automatic Persisted Queries work with hybrid cache mode#2727
spawnia merged 2 commits into
nuwave:masterfrom
Kauto:automatic_persisted_queries_work_with_hybrid_mode

Conversation

@Kauto
Copy link
Copy Markdown
Contributor

@Kauto Kauto commented Nov 28, 2025

I had a problem with production servers when enabling hybrid mode. The webpage uses APQ and when locking up the query in the cache, the content is a "string" instead of a "DocumentNode":

[2025-11-28 14:32:34] production.ERROR: Nuwave\Lighthouse\GraphQL::loadPersistedQuery(): Return value must be of type GraphQL\Language\AST\DocumentNode, string returned {"userId":18,"exception":"[object] (TypeError(code: 0): Nuwave\\Lighthouse\\GraphQL::loadPersistedQuery(): Return value must be of type GraphQL\\Language\\AST\\DocumentNode, string returned at /var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php:330)
[stacktrace]
#0 /var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php(263): Nuwave\\Lighthouse\\GraphQL->loadPersistedQuery()
#1 /var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php(216): Nuwave\\Lighthouse\\GraphQL->executeOperation()
#2 /var/www/app/vendor/nuwave/lighthouse/src/Support/Utils.php(108): Nuwave\\Lighthouse\\GraphQL->{closure:Nuwave\\Lighthouse\\GraphQL::executeOperationOrOperations():216}()
#3 /var/www/app/vendor/nuwave/lighthouse/src/GraphQL.php(214): Nuwave\\Lighthouse\\Support\\Utils::mapEach()
#4 /var/www/app/vendor/nuwave/lighthouse/src/Http/GraphQLController.php(32): Nuwave\\Lighthouse\\GraphQL->executeOperationOrOperations()
#5 /var/www/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(46): Nuwave\\Lighthouse\\Http\\GraphQLController->__invoke()
[...]
"}
  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

Changes

I updated the function to use the new queryCache and thus always use the correct method to load the DocumentNode. I added a test to detect this error in the future.

@Kauto Kauto force-pushed the automatic_persisted_queries_work_with_hybrid_mode branch 2 times, most recently from b94482c to 06ebaab Compare November 28, 2025 17:06
@Kauto Kauto force-pushed the automatic_persisted_queries_work_with_hybrid_mode branch from 06ebaab to 3c0548c Compare December 2, 2025 14:16
@spawnia spawnia added the bug An error within Lighthouse label Dec 2, 2025
@spawnia spawnia self-requested a review December 2, 2025 18:47
@spawnia
Copy link
Copy Markdown
Collaborator

spawnia commented Dec 2, 2025

@Kauto Looks pretty good. Please check the failing test cases - probably just need to change the fn(): never to function (): void {.

Copy link
Copy Markdown
Collaborator

@spawnia spawnia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, nicely done

@spawnia spawnia merged commit 910a218 into nuwave:master Dec 5, 2025
62 checks passed
@spawnia
Copy link
Copy Markdown
Collaborator

spawnia commented Dec 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An error within Lighthouse

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants