urql version & exchanges:
urql: 1.9.7
@urql/exchange-persisted-fetch: 0.1.0
Steps to reproduce
preferGetMethod: true or not.const client = createClient({
url: "http://localhost:3001/graphql",
exchanges: [
dedupExchange,
cacheExchange,
persistedFetchExchange,
fetchExchange,
],
preferGetMethod: true,
});
Every page load, it sends an initial request with the following query params:
variables: {"where":{"url":"http://localhost:3000/"}}
extensions: {"persistedQuery":{"sha256Hash":"261d8cf2da51840aad856147ca6af3e8b358b5d81b509a50292112df4e7347a3","version":1}}
This is correct. The next request, however, has the query parameters
query: query GetPageBookmarkCount($where: PageWhereUniqueInput!) {
pageBookmarkCount(where: $where)
}
variables: {"where":{"url":"http://localhost:3000/"}}
which correctly executes the query, but doesn't result in the query being persisted to the hash.
In the apollo docs, there's an intermediary second step where the query gets stored the cache: curl -g 'http://localhost:4000/?query={__typename}&extensions={"persistedQuery":{"version":1,"sha256Hash":"ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38"}}' that doesn't seem to be happening.
Expected behavior
Persisted queries get saved to cache after the first request
Actual behavior
Persisted queries never get saved to cache
Here is a codesandbox that also exhibits this behavior: https://codesandbox.io/s/bold-field-l2d2v
It sais {"errors":[{"message":"PersistedQueryNotFound", this means that the exchange will fallback to normal queries instead. Maybe this is turned off on your reproduction server.
Oh okay I see, there are two ways of persisted queries in that case, we'll need to add something like this:
case 'persistedNotFound':
Rerun query with queryText
I suppose the problem here was that a spec doesn鈥檛 exist, so we haven鈥檛 done a lot of testing (hence it being a 0.1.0)
I think I鈥檒l spin up a persisted queries testing API so we can validate a fix to the library correctly 馃憤
I finally found the expected behaviour down here in the readme: https://github.com/apollographql/apollo-link-persisted-queries?files=1#protocol
This behaviour is defined in "Missing hash path", Step 4:
Client sends both hash and query string to Server
The fix has been released in @urql/[email protected]
Most helpful comment
The fix has been released in @urql/[email protected]