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

feat(typescript-react-apollo): support useBackgroundQuery and useLoadableQuery #815

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

draftcode
Copy link

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
#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)
  • 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

  • yarn test
  • yarn run generate:examples:cjs
  • yarn run generate:examples:esm
  • (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:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • 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
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • 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...

…ableQuery

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
dotansimha#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.

Follow up to
dotansimha#388.
Fixes dotansimha#477.
Copy link

changeset-bot bot commented Aug 7, 2024

⚠️ No Changeset found

Latest commit: b5a7f64

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

@EfstathiadisD
Copy link

When do we plan to merge this? It would be super useful. Thanks!

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.

2 participants