Urql: @urql/exchange-persisted-fetch doesn't persist the query

Created on 28 Apr 2020  路  4Comments  路  Source: FormidableLabs/urql

urql version & exchanges:
urql: 1.9.7
@urql/exchange-persisted-fetch: 0.1.0

Steps to reproduce

  1. Using this urql client config. Note that I see the same behavior regardless of whether I'm setting preferGetMethod: true or not.
const client = createClient({
  url: "http://localhost:3001/graphql",
  exchanges: [
    dedupExchange,
    cacheExchange,
    persistedFetchExchange,
    fetchExchange,
  ],
  preferGetMethod: true,
});
  1. Load app and run against an Apollo Server. Observe that queries are never actually persisted.

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

bug 馃悰

Most helpful comment

The fix has been released in @urql/[email protected]

All 4 comments

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]

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  路  4Comments

Andrew-Talley picture Andrew-Talley  路  4Comments

alexraginskiy picture alexraginskiy  路  3Comments

kitten picture kitten  路  4Comments

wodnjs6512 picture wodnjs6512  路  3Comments