Currently, @urql/exchange-persisted's options.preferGetForPersistedQueries doesn't allow for persistedOperation.context.preferGetMethod to be set to true or 'within-url-limit', and instead sets persistedOperation.context.preferGetMethod to 'force' when options.preferGetForPersistedQueries is true. This leads to broken GET requests when queries become massive.
Another issue was that although the TSDocs suggest that the default value of options.preferGetForPersistedQueries is true, this wasn't reflected in the logic.
Set of changes
In @urql/exchange-persisted:
The type of options.preferGetForPersistedQueries has changed from boolean | undefined to match the value of the Client's preferGetMethod option, which includes 'force' and 'within-url-limit'.
Sets a default value of options.preferGetForPersistedQueries (to true) to match the TSDocs.
When options.preferGetForPersistedQueries is true, we no longer set operation.context.preferGetMethod to 'force'. Instead, operation.context.preferGetMethod is set to true.
This extends to all values of options.preferGetForPersistedQueries. The value set there will be the value set in operation.context.preferGetMethod.
Removes a check on the value of preferGetForPersistedQueries before setting persistedOperation.context.preferGetMethod. This allows persistedOperation.context.preferGetMethod to be set to false if options.preferGetForPersistedQueries is set to false.
Adds unit tests to validate the changes described here.
Summary
This PR aims to resolve https://github.com/urql-graphql/urql/issues/3185.
Currently,
@urql/exchange-persisted
'soptions.preferGetForPersistedQueries
doesn't allow forpersistedOperation.context.preferGetMethod
to be set totrue
or'within-url-limit'
, and instead setspersistedOperation.context.preferGetMethod
to'force'
whenoptions.preferGetForPersistedQueries
istrue
. This leads to broken GET requests when queries become massive.Another issue was that although the TSDocs suggest that the default value of
options.preferGetForPersistedQueries
istrue
, this wasn't reflected in the logic.Set of changes
In
@urql/exchange-persisted
:options.preferGetForPersistedQueries
has changed fromboolean | undefined
to match the value of the Client'spreferGetMethod
option, which includes'force'
and'within-url-limit'
.options.preferGetForPersistedQueries
(totrue
) to match the TSDocs.options.preferGetForPersistedQueries
istrue
, we no longer setoperation.context.preferGetMethod
to'force'
. Instead,operation.context.preferGetMethod
is set totrue
.options.preferGetForPersistedQueries
. The value set there will be the value set inoperation.context.preferGetMethod
.preferGetForPersistedQueries
before settingpersistedOperation.context.preferGetMethod
. This allowspersistedOperation.context.preferGetMethod
to be set tofalse
ifoptions.preferGetForPersistedQueries
is set tofalse
.