Conversation
src/utils/error.ts
Outdated
| }: { | ||
| networkError?: Error; | ||
| graphQLErrors?: Array<string | GraphQLError | Error>; | ||
| graphQLErrors?: graphqlError[]; |
There was a problem hiding this comment.
This doesn't seem strictly necessary; If there's a rule for it, I'd say we should maybe disable it 🤔 It seems to be a good rule of thumb but often we really don't care about a type alias, especially when, like here, we only convert all of these and normalise them anyway
There was a problem hiding this comment.
Yep, this was just a linting flag, I'll switch it back 👍
| @@ -1,3 +1,13 @@ | |||
| import { mount } from 'enzyme'; | |||
There was a problem hiding this comment.
Same here, just reordering to appease lint, but happy to reorder back 😅
| @@ -1,3 +1,4 @@ | |||
| /* eslint-disable @typescript-eslint/no-use-before-define */ | |||
There was a problem hiding this comment.
I actually did disable the rules in the exchanges since it would've produced a very large diff. So I guess we should have a discussion about whether we disable this rule globally or follow it globally.
There was a problem hiding this comment.
I think in some cases we should just reorder it in a separate commit, so we have an easily trackable change history of what happened in these files
There was a problem hiding this comment.
🆒I'll revise so that this commit just disables ESLint and we can reorder in a separate commit.
kitten
left a comment
There was a problem hiding this comment.
I really only have a couple of nits, but my opinion would be that we could still address them in a separate PR; this way @andyrichardson and myself could open PRs about any opinions/discussions we'd like to have on this and have those discussions separately. But since the changes are minimal right now, I don't expect that to happen a lot 😅
src/hooks/useQuery.ts
Outdated
| unsubscribe.current = teardown; | ||
| }, | ||
| [request.key, args.skip, args.requestPolicy] | ||
| [request, client, args.skip, args.requestPolicy] |
There was a problem hiding this comment.
client and request were both flagged as needing to be included here because they're both accessed in this useCallback. client comes out of context so I think it should be included for safety. It should only ever get set once, so it wasn't affecting behavior at all previously because it never changed.
There was a problem hiding this comment.
Ah, damn, ok this is a huge issue and actually introduces a bug. The request.key is the hash of the request, but we're recreating the instance on every mount on purpose, since we can't know if a DocumentNode or variables instance has changed.
There was a problem hiding this comment.
Ah ok. Does that not get covered by the useMemo above, which gets recalculated whenever args.query or args.variables changes? I guess the way I see the dependencies working is:
useMemo – creates request, recalculates whenever args.query (DocumentNode) or args.variables (variables) changes.
useCallback – has a dependency on request generated by useMemo, so it should get recalculated whenever args.query or args.variables changes (which sounds like is the case for which a new hash gets generated into request.key).
useEffect – gets called whenever executeQuery (the useCallback) gets recalculated.
Just want to make sure I really grok the problem, as the hooks dependencies seem correct. Happy to change back to request.key tho!
There was a problem hiding this comment.
Not really, because we don't want to rely on reference equality here. Variables are likely to be recreated by the user and forcing them to memo those can be a burden. That should be an optimisation that they can optionally apply.
The same goes for misused graphql- tag stuff, where reference equality is often guaranteed but not always
There was a problem hiding this comment.
Gotcha, I'll ensure we use request.key here and we can disable the hooks lint warning.
src/hooks/useSubscription.ts
Outdated
| unsubscribe = teardown; | ||
| }, [request.key]); | ||
| unsubscribe.current = teardown; | ||
| }, [request, handler, client]); |
There was a problem hiding this comment.
Same here, both client and handler are accessed in this useCallback and it makes sense to me that they're included.
bd254e5 to
4dd84af
Compare
4dd84af to
caedc75
Compare
|
@kitten @andyrichardson cleaned this up a bit more and added a few more tests cases so let me know how you feel about things! The remaining discussion items seem to be:
Happy to make changes addressing the above here or in a follow up! |
kitten
left a comment
There was a problem hiding this comment.
All seems well 👌 I just wish we could make request.key work without adding the magic eslint comment, but we can revisit that another time 😅
|
@parkerziegler I think we could rename it to I think the tests are 👌. It's definitely more error prone to work with "act" or try to make updates behave like they usually would. Let's see how it works out. We can always delete the old tests if they start failing and are falling behind. |
This PR does a few things as a follow up to #237.
Migrates the codebase off of
tslintto@typescript-eslint🎉. This is great, because it allows us to plug into the whole ESLint ecosystem as we like. I ported over all of our existing TSLint rules using the handy roadmap provided by@typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md. I also fixed our files up just a bit to match the new world order, but most changes are just switching fromtslint:disabletoeslint-disable.Fixes some of our hooks dependencies to match the lint rules provided by Dan's
react-hooksplugin. Our tests still pass with this change, but we'll want to doubly verify that hooks behave as expected.Added some example tests for
useQueryusingreact-hooks-testing-library. This more serves as a proof of concept of what tests for hooks w/outreact-test-rendererandenzymemight look like. The benefits I see are:renderHookwill handle this for us.react-hooks-testing-libraryreturns us arefcontaining what our hook returns, so we get a nice, easy way to access the return values of our custom hooks.waitForNextUpdate– this API allows us to wait untiluseEffectcalls have run and the side effect generated has completed. This feels nice because it means we don't have to callwrapper.updatemultiple times to see our hook values update, which feels a little hacky and arbitrary.rerender– this API allows us to rerender our hook (or rather, the component containing our hook) and pass it new values to see how it responds. Again, this feels a bit cleaner than multiplewrapper.updatecalls w/ different props.I'm not super attached to using
react-hooks-testing-library, but wanted to show its API in passing tests so we can make a decision about what we like. If we want to try anenzymeupgrade to see ifmountis working I'm open to it, I've just experienced pain w/ waiting onenzymemaintenance. If we want to punt on test APIs later and just merge the hooks modifications and linting I'm also totally good with that! Also @andyrichardson @kitten I know we talked about renaming theskipprop in #237, so let's continue that discussion here.