vishalbalaji / trpc-svelte-query-adapter

A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.
71 stars 7 forks source link

trpc.(some procedure).useMutation() arguments misplaced #7

Closed sharmapukar217 closed 1 year ago

sharmapukar217 commented 1 year ago

when using trpc.procedure.useMutation({ onMutate() {}, onError() {}, ...rest }) trpc.procedure.useMutation(undefined, { onMutate() {}, onError() {}, ...rest }) seems to be working but then typescript shows error

vishalbalaji commented 1 year ago

Are you saying that the first example works and the second doesn't? If so, this is how it is supposed to work and it was wrong initially, which has been fixed now. You don't pass the input to useMutation, but instead when you call the .mutate method. Refer to https://trpc.io/docs/useMutation for usage instructions. Does this resolve the issue?

If not, could you please add a comment with the error that typescript is throwing?

sharmapukar217 commented 1 year ago

The first one doesn't work. The second one works but typescript shows error

sharmapukar217 commented 1 year ago

I know the variables are passed to . mutate () function.. this might be the problem of svelte query because the first params of onMutate() seems to hold variables passed to . mutate function which is the not case. According to react query doc, the first param of onMutate is data

vishalbalaji commented 1 year ago

Hmmm, that's peculiar... Either way, there was a major update a few days ago where I restructured a bunch of stuff. Could you try updating to v2.0.0 and let me know if the issue is still present?

sharmapukar217 commented 1 year ago

Sure I'll check it and inform you soon

sharmapukar217 commented 1 year ago

v2 seems to have more errors. typescript shows trpc().useContext() is not present in procedure something like this.

vishalbalaji commented 1 year ago

v2 has had some breaking changes. Tje procedures are called create<procedure> now to be more consistent with tanstack query. There was a note in the README of the previous version that this would be done.

Its createContext now instead of useContext.

sharmapukar217 commented 1 year ago

Oh my bad. V2 is working fine 😊 closing the issue

sharmapukar217 commented 1 year ago

Error: Property 'createInfiniteQuery' does not exist on type 'QueryProcedures<any, { users: SerializeObject<UndefinedToOptional<Omit<User, "password">>>[]; pageParams: SerializeObject<UndefinedToOptional<{ endCursor: any; startCursor: string; }>>; }, TRPCClientErrorLike<...>>'.

what does this mean? The data is showing but typescript is giving such error

vishalbalaji commented 1 year ago

Could you share your trpc router and how you called it in the component so that I can take a look?