Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(vue-urql) - Add Tests #1153

Merged
merged 6 commits into from
Nov 15, 2020
Merged

(vue-urql) - Add Tests #1153

merged 6 commits into from
Nov 15, 2020

Conversation

LinusBorg
Copy link
Contributor

Summary

This PR adds tests for:

  • useMutation
  • useQuery
  • useSubscription

Set of changes

  • The added tests cover the same cases as the svelte implementation.
  • I had to add jest to the package's tsconfig type option in order to stop TS from complaining, this should not have any impact outside of the vue-urql package.
  • This is a draft PR for now as I came across some problems to test useQuery().then() behavior, and I'm not certain what the desired behavior here should be. Please see the code comments

This only adds tests, so I didn't create a changeset. I can provide one if that's still required for this kind of PR.

@changeset-bot
Copy link

changeset-bot bot commented Nov 14, 2020

⚠️ No Changeset found

Latest commit: f31f99b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@LinusBorg LinusBorg marked this pull request as draft November 14, 2020 13:30

const query = await useQuery({
query: `{ test }`,
// pause: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's interesting! I think this is because we can liken this behaviour to suspense in React, so once useQuery's promise resolves and we subscribe again we don't have a result, since no cacheExchange is used.

Adding the appropriate exchanges however is not what we want though. While it would fix this, the cache doesn't cache errored results for instance, so instead we'll have to copy some code from react-urql's useQuery where the result is cached just for the suspended stream for the next rerender after suspending.

I can take a look at fixing this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main problem here was that I wasn't sure what the use case of making it " thenable" is, so I wasn't sure what an appropriate fix would be.

Am I understanding correctly that this is supposed to support Vue's version of Supsense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think I also don't quite know enough unfortunately quite yet to fix this. So it is indeed to support Vue's version of suspense, so we'd like to await the first result that executeQuery may yield but during normal execution we'd also like future results to still update the component.

I'm not quite clear on how the component lifecycle functions once Vue suspends, so it'd be interesting to know whether the lifecycle aborts when it does.

I think we may get into some trouble here with our isThenable flag, but essentially the idea was always to return the promise, resolve it on a result, and otherwise still keep a subscription active to update the result refs passively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I'll think a bit about it as well.


expect(query.fetching).toBe(true);

subject.next({ data: { test: true } });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure if this test is adequate for polling. Maybe we can use some timer mocks in the executeQuery's mockImplementation so it really sends a couple of data points after timeouts?

then again, would that really improve the tests? Not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is adequate, since all it'd have to support is results being actively pushed into the useQuery subscription

@LinusBorg
Copy link
Contributor Author

@kitten Suggestion: we merge these tests as they are, with the skipped one, just so we have some basic checks in place for the rest of the functionality.

Then we can work on solving the issue with that Promise for Suspense without breaking stuff accidentally.

@LinusBorg LinusBorg marked this pull request as ready for review November 15, 2020 14:20
Copy link
Collaborator

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some awesome work 🎉 I agree @LinusBorg let's merge this as is, having tests in place is already awesome

@JoviDeCroock JoviDeCroock merged commit 72c59ce into urql-graphql:main Nov 15, 2020
@LinusBorg LinusBorg deleted the vue-urql-tests branch November 15, 2020 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants