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: mutate shortcut #396

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Netail
Copy link
Contributor

@Netail Netail commented Nov 29, 2024

As there's a query shortcut, it would be nice to have a mutate shortcut as well. Used in server actions :)

@Netail Netail requested a review from a team as a code owner November 29, 2024 13:14
Copy link

netlify bot commented Nov 29, 2024

👷 Deploy request for apollo-client-nextjs-docmodel pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6115c3e

Copy link

pkg-pr-new bot commented Nov 29, 2024

npm i https://pkg.pr.new/apollographql/apollo-client-nextjs/@apollo/client-react-streaming@396
npm i https://pkg.pr.new/apollographql/apollo-client-nextjs/@apollo/experimental-nextjs-app-support@396

commit: 6115c3e

Copy link

relativeci bot commented Nov 29, 2024

#372 Bundle Size — 1.25MiB (0%).

6115c3e(current) vs c125a08 main#352(baseline)

Warning

Bundle contains 1 duplicate package – View duplicate packages

Bundle metrics  Change 1 change
                 Current
#372
     Baseline
#352
No change  Initial JS 1016.91KiB 1016.91KiB
No change  Initial CSS 70B 70B
Change  Cache Invalidation 4.36% 24.97%
No change  Chunks 34 34
No change  Assets 59 59
No change  Modules 636 636
No change  Duplicate Modules 106 106
No change  Duplicate Code 4.66% 4.66%
No change  Packages 26 26
No change  Duplicate Packages 1 1
Bundle size by type  no changes
                 Current
#372
     Baseline
#352
No change  JS 1.24MiB 1.24MiB
No change  Other 9.09KiB 9.09KiB
No change  CSS 70B 70B

Bundle analysis reportBranch Netail:feat/mutate-shortcutProject dashboard


Generated by RelativeCIDocumentationReport issue

@phryneas
Copy link
Member

Hi @Netail, thank you for the PR!

Before I get this merged, I'll have to do some investigation - I very roughly remember that the behaviour of registerApolloClient in Server Actions changed between versions of Next.js, so I'll have to double-check that everything works as intended there before we get this change in that encourages usage of rAC in server actions. (We never explicitly targeted them until now.)

I hope I can get to that next week, so please have a bit of patience :)

@Netail
Copy link
Contributor Author

Netail commented Nov 29, 2024

Hi @Netail, thank you for the PR!

Before I get this merged, I'll have to do some investigation - I very roughly remember that the behaviour of registerApolloClient in Server Actions changed between versions of Next.js, so I'll have to double-check that everything works as intended there before we get this change in that encourages usage of rAC in server actions. (We never explicitly targeted them until now.)

I hope I can get to that next week, so please have a bit of patience :)

That's completely fine, please let me know, we current use getClient().mutate with NextJS 14.2.x without issues, but could ofc be different with Next 15 :)

Copy link

changeset-bot bot commented Dec 27, 2024

⚠️ No Changeset found

Latest commit: 6115c3e

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
Name Type
@apollo/client-react-streaming Patch
@apollo/experimental-nextjs-app-support Patch

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

@Netail
Copy link
Contributor Author

Netail commented Jan 12, 2025

Before I get this merged, I'll have to do some investigation - I very roughly remember that the behaviour of registerApolloClient in Server Actions changed between versions of Next.js, so I'll have to double-check that everything works as intended there before we get this change in that encourages usage of rAC in server actions. (We never explicitly targeted them until now.)

Not only in server-actions btw, you could also use mutate in API routes (route.ts files)

Copy link

vercel bot commented Jan 12, 2025

@Netail is attempting to deploy a commit to the Apollo Client - Next package - integration tests Team on Vercel.

A member of the Team first needs to authorize it.

@phryneas
Copy link
Member

Not only in server-actions btw, you could also use mutate in API routes (route.ts files)

Oh gosh, honestly that sounds dangerous - it would be akin to mutating in GET REST endpoints - imagine the user has their browser set to auto-refresh the page regularly and it causes things to get mutated on the server all the time, or imagine a web crawler hits that mutation.

@Netail
Copy link
Contributor Author

Netail commented Jan 13, 2025

Oh gosh, honestly that sounds dangerous - it would be akin to mutating in GET REST endpoints - imagine the user has their browser set to auto-refresh the page regularly and it causes things to get mutated on the server all the time, or imagine a web crawler hits that mutation.

Not that easily hahaha, there should be some logic beforehand (maybe some validation and/or authorization), also can be set on different HTTP methods. But it was just an example of where such mutation function could be used. It's already possible ofc, with getClient().mutate

@phryneas
Copy link
Member

Yeah, it's possible, I'm just not sure if it should be easily possible 😅

On a sidenote: I'm sorry that this is taking so long - our team got a bit smaller end of last year and while my focus is very much on this repo right now, conceptually it's very far away from Next server actions - I'm working on the React Router and TanStack Start integrations.
So thank you for the patience and I'm sorry, but it will be some time until I can really get back to this.

@Netail
Copy link
Contributor Author

Netail commented Jan 13, 2025

So thank you for the patience and I'm sorry, but it will be some time until I can really get back to this.

No problem, take your time :)

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