Skip to content

Update createUtils proxy to include path in context #54

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

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trpc-svelte-query-adapter",
"version": "2.3.12",
"version": "2.3.13",
"description": "A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.",
"keywords": [
"trpc",
Expand Down
9 changes: 6 additions & 3 deletions @lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ type GetQueryKey<TInput = undefined> = [TInput] extends [undefined | void]
* Method to extract the query key for a procedure
* @param type - defaults to `any`
*/
[Procedure.queryKey]: (input: TInput, type?: QueryType) => TRPCQueryKey;
[Procedure.queryKey]: (input?: TInput, type?: QueryType) => TRPCQueryKey;
} & {};

function getClientArgs<TOptions>(
Expand Down Expand Up @@ -942,6 +942,7 @@ const utilProcedures: Record<
},
[Util.Query.invalidate]: ({ path, queryClient, key }) => {
return (input?: any, filters?: any, options?: any) => {
console.log(path, input, getQueryType(key as any));
const queryKey = getQueryKeyInternal(
path,
input,
Expand Down Expand Up @@ -1087,7 +1088,9 @@ function createUtilsProxy(ctx: WrapperContext) {
if (key === Util.Query.client) return ctx.baseClient;

if (hasOwn(utilProcedures, key)) {
return utilProcedures[key](Object.assign(ctx, { key }));
return utilProcedures[key](
Object.assign(ctx, { key, path: this.path })
);
}

return this.nest(() => {});
Expand Down Expand Up @@ -1132,7 +1135,7 @@ const procedures: Record<
(ctx: WrapperContext) => any
> = {
[Procedure.queryKey]: ({ path }) => {
return (input: any, opts?: any) => getQueryKeyInternal(path, input, opts);
return (input?: any, opts?: any) => getQueryKeyInternal(path, input, opts);
},
[Procedure.query]: ({ path, client, abortOnUnmount, queryClient }) => {
return (input: any, opts?: any) => {
Expand Down