Why does firstvaluefrom from watchedquery return undefined

Hi guys,

When migrating from v3 to v4, in this documentation it says result is deprecated for watchQuery : ObservableQuery - Apollo GraphQL Docs
and also in v4 doc: ObservableQuery - Apollo GraphQL Docs

I did some tests and applied the same example using firstValueFrom and from in this example:

firstValueFrom(from(watchedQuery)).then(...) // undefined
firstValueFrom(watchedQuery.pipe()).then(...) // works
firstValueFrom(from(watchedQuery).pipe()).then(...) // works

Any idea why? Is it a documentation typo?

That is very curious, we are using

await firstValueFrom(from(obsQuery));

in at least 10 different tests and it works everywhere.

We are testing with rxjs versions 7.3.0 and 7.8.1 - which version are you using?

@apolloapolloapolloapolloapolloapolloapolloapollo/client@4.0.9 and rxjs@7.8.2

I will try 7.8.1 to see if I notice a change

Update

Ok so no change even if I use 7.8.1

I did a quick search of the code in the repo and I do see that you use firstValueFrom(from()) in your tests but they don’t check the result.

Example here apollo-client/src/_tests_/mutationResults.ts at 7ea886e41f8cf1461de48f2c690466e493c70a5e · apollographql/apollo-client

And here: apollo-client/src/react/ssr/prerenderStatic.tsx at 7ea886e41f8cf1461de48f2c690466e493c70a5e · apollographql/apollo-client
You do pipe() without from

Thanks!

Another thought, are you maybe polyfilling Symbol.observable in some way?

I don’t think so but I will check to be sure in case.

Ok so I don’t think the issue is your documentation.

I think the issue is related to my migration, for some reason the watch query is trying to send queries to the wrong URL.

Thanks for your help.

Update: This was my problem, in case anyone has the same issue when migrating.

Migrating to Apollo Client 4.0 - Apollo GraphQL Docs

2 Likes