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: call TRPCProxyClient methods with .apply() #3964

Closed
1 task done
atoy40 opened this issue Mar 9, 2023 · 0 comments · Fixed by #3973
Closed
1 task done

feat: call TRPCProxyClient methods with .apply() #3964

atoy40 opened this issue Mar 9, 2023 · 0 comments · Fixed by #3973
Labels
✅ accepted-PRs-welcome Feature proposal is accepted and ready to work on @trpc/client

Comments

@atoy40
Copy link
Contributor

atoy40 commented Mar 9, 2023

Provide environment information

System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
npmPackages:
@tanstack/react-query: ^4.3.8 => 4.6.0
@trpc/client: ^10.14.1 => 10.14.1
@trpc/next: ^10.14.1 => 10.14.1
@trpc/react-query: ^10.14.1 => 10.14.1
@trpc/server: ^10.14.1 => 10.14.1
next: ^13.2.1 => 13.2.1
react: ^18.2.0 => 18.2.0
typescript: ^4.8.3 => 4.8.3

Describe the bug

TRPCProxyClient functions query, mutate and subscribe cannot be called trough the apply() method.
So you cannot pass the function to a library that call it later using apply (for example redux-saga call effect)
Error is :
TypeError: client[procedureType] is not a function

example is using this :
trpcProxyClient.greeting.query.apply(undefined, { name: "world" });
instead of :
trpcProxyClient.greeting.query({ name: "world" });

Link to reproduction

https://stackblitz.com/edit/github-zdwdjx?file=src/pages/index.tsx

To reproduce

Just use the stackblitz link, the bug is "active" by default

Additional information

It doesn't work, because the path variable in :

return createRecursiveProxy(({ path, args }) => {

contains ["query", "apply"] instead of just ["query"]
So clientCallType contains "apply" and not "query" at :
const clientCallType = pathCopy.pop()! as keyof DecorateProcedure<

I think the only change to do it to check if apply is the last entry in path array and remove it ?

Thanks for help

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!
@KATT KATT changed the title bug: TRPCProxyClient functions query, mutate and subscribe cannot be called trough the apply() method feat: call TRPCProxyClient methods with .apply() Mar 11, 2023
@KATT KATT added @trpc/client ✅ accepted-PRs-welcome Feature proposal is accepted and ready to work on and removed 🐛 bug: unconfirmed labels Mar 11, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✅ accepted-PRs-welcome Feature proposal is accepted and ready to work on @trpc/client
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants