jotaijs / jotai-apollo

Apollo graphql client integration for jotai :rocket: :ghost:
MIT License
50 stars 4 forks source link

Use watchQuery for atomsWithQuery #10

Closed dsonck92 closed 1 year ago

dsonck92 commented 1 year ago

Closes: #9

codesandbox-ci[bot] commented 1 year ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7617b923e73009c366fb08bd8907002588b75fbc:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
Next.js Configuration
Next.js with custom Babel config Configuration
React with custom Babel config Configuration
dsonck92 commented 1 year ago

Since it's already using an Observer, and the watchQuery returns an Observer as well, all the logic can be reduced to just calling client.watchQuery. At least this fixes the refresh on my own project.

I would consider any further features, other than just plainly handling the observer, out of scope and to be dealt with when the need arises.

dsonck92 commented 1 year ago

Ah yes, it seems like there was a query mock in place that doesn't work anymore. I will try to rewrite the tests to use MockLink from apollo instead so we can build on a more vanilla ApolloClient later today.

dsonck92 commented 1 year ago

Seems like the tests so far also get simplified by leveraging the MockLink. Currently tackling the refetch test but then it should work.

dsonck92 commented 1 year ago

Locally I got all tests running. Main changes are:

Though I will say, I don't exactly know what that last function is really supposed to test. Though it does show it can retrigger the query getting function.