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

Add support for passing in client into useFragment #11525

Merged
merged 14 commits into from
Feb 1, 2024

Conversation

vezaynk
Copy link
Contributor

@vezaynk vezaynk commented Jan 25, 2024

My use-case requires passing in client explicitly to all hooks. This PR introduces support for it in useFragment, which was missing it.

@apollo-cla
Copy link

@vezaynk: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link

netlify bot commented Jan 25, 2024

👷 Deploy request for apollo-client-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1684e9c

Copy link

changeset-bot bot commented Jan 25, 2024

🦋 Changeset detected

Latest commit: 1684e9c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

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

@vezaynk vezaynk marked this pull request as ready for review January 25, 2024 22:03
@jerelmiller
Copy link
Member

Hey @vezaynk 👋

Appreciate the PR! Before we move forward with this, would you mind writing a couple tests for this? We want to be sure that future changes to our hooks don't break existing functionality.

You can find the useFragment tests here: https://github.com/apollographql/apollo-client/blob/main/src/react/hooks/__tests__/useFragment.test.tsx

If you'd like an example of how we test some of our other hooks that allow a client override, here's an example from useSuspenseQuery:

it("allows the client to be overridden", async () => {
const { query } = useSimpleQueryCase();
const globalClient = new ApolloClient({
link: new ApolloLink(() =>
Observable.of({ data: { greeting: "global hello" } })
),
cache: new InMemoryCache(),
});
const localClient = new ApolloClient({
link: new ApolloLink(() =>
Observable.of({ data: { greeting: "local hello" } })
),
cache: new InMemoryCache(),
});
const { result, renders } = renderSuspenseHook(
() => useSuspenseQuery(query, { client: localClient }),
{ client: globalClient }
);
await waitFor(() =>
expect(result.current.data).toEqual({ greeting: "local hello" })
);
expect(renders.frames).toMatchObject([
{
data: { greeting: "local hello" },
networkStatus: NetworkStatus.ready,
error: undefined,
},
]);
});

Assuming we move forward with this, we will likely slate this for our 3.10 release as its new functionality and we are in a code freeze for 3.9. 3.9 will be released as soon as we finish documentation, which should be early next week.

Thank you!

@jerelmiller jerelmiller added 👩‍🔬 needs-more-tests 🥚 backwards-compatible for PRs that do not introduce any breaking changes labels Jan 25, 2024
@vezaynk
Copy link
Contributor Author

vezaynk commented Jan 25, 2024

@jerelmiller Can this be shipped as a patch after the release? It's a very minor API extension that mirrors what every other hook does. It's not really "new functionality".

I'm happy to put more work into this, but I would appreciate being able to download this from npm afterwards.

@jerelmiller
Copy link
Member

jerelmiller commented Jan 25, 2024

@vezaynk I'll discuss with the team and let you know. We have a team meeting first thing Monday morning.

In the meantime, if you need this functionality, I'd recommend using patch-package in your setup.

Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Hey @vezaynk 👋

I'm still waiting on confirmation about when we'd like to release this. One of our maintainers has been out recently, so as soon as we get a consensus, I'll let you know.

In the mean time, I wanted to get you a proper review. Aside from adding tests, the only thing that I'd like to see is a docblock for the client option.

Appreciate the contribution!

src/react/hooks/useFragment.ts Outdated Show resolved Hide resolved
src/react/hooks/useFragment.ts Outdated Show resolved Hide resolved
vezaynk and others added 3 commits January 31, 2024 20:34
Co-authored-by: Jerel Miller <jerelmiller@gmail.com>
Co-authored-by: Jerel Miller <jerelmiller@gmail.com>
@vezaynk vezaynk requested a review from a team as a code owner February 1, 2024 01:44
@vezaynk
Copy link
Contributor Author

vezaynk commented Feb 1, 2024

@jerelmiller Thanks for the review. I have added the suggestions and wrote 2 tests.

Copy link
Contributor

@alessbell alessbell left a comment

Choose a reason for hiding this comment

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

Thanks for adding those tests, @vezaynk! This is super close to merging - the team synced now that we're all back online and we'll get it out in the next patch 🚀

Added a few minor comments, one question for @phryneas to make sure the docblock is good to go (edit: we're good to go here) and the tests are failing on CI because they're missing one thing: client?: ApolloClient<any>; needs to be added to the type test "UseFragmentOptions interface shape" at the bottom of useFragment.test.tsx.

src/react/hooks/useFragment.ts Outdated Show resolved Hide resolved
src/react/hooks/__tests__/useFragment.test.tsx Outdated Show resolved Hide resolved
src/react/hooks/__tests__/useFragment.test.tsx Outdated Show resolved Hide resolved
src/react/hooks/useFragment.ts Show resolved Hide resolved
vezaynk and others added 2 commits February 1, 2024 10:06
Co-authored-by: Alessia Bellisario <github@bellisar.io>
Co-authored-by: Alessia Bellisario <github@bellisar.io>
@alessbell
Copy link
Contributor

Hi @vezaynk 👋 there's still one test failing ("UseFragmentOptions interface shape" at the bottom of useFragment.test.tsx). Let me know if you were going to circle back to that, otherwise it's no problem for me to push up the one line fix and merge, thanks!

@vezaynk
Copy link
Contributor Author

vezaynk commented Feb 1, 2024

@alessbell @jerelmiller I think I addressed everything

@alessbell alessbell added the auto-cleanup 🤖 label Feb 1, 2024
@jerelmiller
Copy link
Member

Thanks so much @vezaynk! As soon as we see the tests pass, we'd be happy to merge this. Don't worry about the failed security scan checks or api extractor checks. We'll handle those 🙂

Thanks so much again for the contribution!

@jerelmiller jerelmiller merged commit dce923a into apollographql:main Feb 1, 2024
27 of 31 checks passed
@github-actions github-actions bot mentioned this pull request Feb 1, 2024
@alessbell
Copy link
Contributor

This has been released in v3.9.3 🎉

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-cleanup 🤖 🥚 backwards-compatible for PRs that do not introduce any breaking changes 🧞‍♂️ enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants