nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.36k stars 438 forks source link

feat: make `loadPersistedQuery` public #2579

Closed jaulz closed 3 months ago

jaulz commented 3 months ago

Changes

This PR will remember persisted queries locally. The idea is related to https://github.com/nuwave/lighthouse/discussions/2561. Right now, I use the StartOperationOrOperations event to determine whether the query is allowed or not. This works fine but previously defined queries will not work anymore as soon as I release another version. Hence, I would like to check first if the query was persisted before:

$query = rescue(fn () => $graphql->loadPersistedQuery($operationId), null, false);

if ($query) {
  return true;
}

This PR makes loadPersistedQuery public and also remembers persisted queries locally to avoid hitting the cache twice.

Please let me know what you think and I can try to implement tests as well.

Breaking changes

n/a

spawnia commented 3 months ago

Can we just make the method public for now?

jaulz commented 3 months ago

@spawnia sure, fine for me 😊 I anyway hope that there will be something built-in to allow pre-defined queries and mutations in the future 😉

spawnia commented 3 months ago

Thank you @jaulz, released with https://github.com/nuwave/lighthouse/releases/tag/v6.40.0.