feat(typescript-react-apollo): support useBackgroundQuery and useLoadableQuery
Description
Implement useBackgroundQuery and useLoadableQuery hooks for React Apollo. These APIs are added in 3.8.0 and 3.9.0 respectively.
Suspense support in Apollo Client provides 5 new hooks as described in https://www.apollographql.com/docs/react/data/suspense/. useSuspenseQuery support was added in
https://github.com/dotansimha/graphql-code-generator-community/pull/434. Among other 4 hooks, useBackgroundQuery and useLoadableQuery are the ones that take a GraphQL document as an argument like other existing hooks. The support for these hooks are added in this change.
Other hooks, useQueryRefHanders and useReadQuery do not take a GraphQL document as an argument, so they do not need to be added as the generated code. Both take the return values of other hooks as an argument, and the types are inferred from it.
Related #477, #388
Type of change
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
Screenshots/Sandbox (if appropriate/relevant):
Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [x] yarn test
- [x] yarn run generate:examples:cjs
- [x] yarn run generate:examples:esm
- [x] (tested and typechecked in our internal repository)
Note that the codegen makes a diff that is not related to this change. If necessary, I can revert them back.
Test Environment:
- OS: Linux 6.10.2-arch1-1 (Arch Linux)
-
@graphql-codegen/typescript-react-apollo: 4.3.0 - NodeJS: 20.16.0
Checklist:
- [x] I have followed the CONTRIBUTING doc and the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
⚠️ No Changeset found
Latest commit: b5a7f64c30a645ca1ba99b59ba91a0a638be7848
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
When do we plan to merge this? It would be super useful. Thanks!
@draftcode Can you resolve the conflicts in your branch so this has a better chance of getting merged?