From 87d0984aba011484dc105b58d7d00fbce64318a1 Mon Sep 17 00:00:00 2001 From: Kyle Mazza Date: Thu, 3 Apr 2025 00:28:36 -0700 Subject: [PATCH 1/4] feat: add mutationkey to allow tracking mutation changes --- src/hook-file.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hook-file.ts b/src/hook-file.ts index 6dcae4b..1f47903 100644 --- a/src/hook-file.ts +++ b/src/hook-file.ts @@ -164,6 +164,7 @@ export class HookFile extends ModuleBuilder { yield ` const queryClient = ${useQueryClient()}();`; yield ` const ${serviceName} = ${this.context.fn(serviceHookName)}()`; yield ` return ${useMutation()}({`; + yield ` mutationKey: ${this.buildQueryKey(httpPath, method)},`; yield ` mutationFn: async (${paramsExpression}) => {`; yield ` const res = await ${guard()}(${serviceName}.${camel( method.name.value, From 63c95c915dc7e6657a2e611549fab0be07fedf88 Mon Sep 17 00:00:00 2001 From: Kyle Mazza Date: Thu, 3 Apr 2025 11:09:27 -0700 Subject: [PATCH 2/4] feat: NEEDS FEEDBACK added method to mutationKey to prevent accidental duplicates --- src/hook-file.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hook-file.ts b/src/hook-file.ts index 1f47903..693725a 100644 --- a/src/hook-file.ts +++ b/src/hook-file.ts @@ -164,7 +164,7 @@ export class HookFile extends ModuleBuilder { yield ` const queryClient = ${useQueryClient()}();`; yield ` const ${serviceName} = ${this.context.fn(serviceHookName)}()`; yield ` return ${useMutation()}({`; - yield ` mutationKey: ${this.buildQueryKey(httpPath, method)},`; + yield ` mutationKey: [${method} ${this.buildQueryKey(httpPath, method)}],`; yield ` mutationFn: async (${paramsExpression}) => {`; yield ` const res = await ${guard()}(${serviceName}.${camel( method.name.value, @@ -481,7 +481,7 @@ export class HookFile extends ModuleBuilder { } if (options?.infinite) { - queryKey.push('{inifinite: true}'); + queryKey.push('{infinite: true}'); } return `[${queryKey.join(', ')}]${ From 48f96a506307508b19be5034a2e4f748ea40e8a2 Mon Sep 17 00:00:00 2001 From: Kyle Mazza Date: Thu, 3 Apr 2025 11:30:10 -0700 Subject: [PATCH 3/4] WIP: add mutationKey property to mutation hooks --- src/hook-file.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hook-file.ts b/src/hook-file.ts index 693725a..475cec7 100644 --- a/src/hook-file.ts +++ b/src/hook-file.ts @@ -160,11 +160,12 @@ export class HookFile extends ModuleBuilder { undefined, method.deprecated?.value, ); + const mutationKey = [this.buildQueryKey(httpPath, method), { method }]; yield `export function ${name}(${optionsExpression}) {`; yield ` const queryClient = ${useQueryClient()}();`; yield ` const ${serviceName} = ${this.context.fn(serviceHookName)}()`; yield ` return ${useMutation()}({`; - yield ` mutationKey: [${method} ${this.buildQueryKey(httpPath, method)}],`; + yield ` mutationKey: ${mutationKey},`; yield ` mutationFn: async (${paramsExpression}) => {`; yield ` const res = await ${guard()}(${serviceName}.${camel( method.name.value, @@ -193,6 +194,8 @@ export class HookFile extends ModuleBuilder { yield ` ...options,`; yield ` });`; yield `}`; + + yield `${name}.mutationKey = ${mutationKey}`; } if (isGet && this.isRelayPaginated(method)) { From 227684ef152ee05a99fab30814d946be6335c3e2 Mon Sep 17 00:00:00 2001 From: Kyle Mazza Date: Thu, 3 Apr 2025 12:40:34 -0700 Subject: [PATCH 4/4] feat: just use the method name as the mutation key dummy --- src/hook-file.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hook-file.ts b/src/hook-file.ts index 475cec7..0b5056d 100644 --- a/src/hook-file.ts +++ b/src/hook-file.ts @@ -160,7 +160,7 @@ export class HookFile extends ModuleBuilder { undefined, method.deprecated?.value, ); - const mutationKey = [this.buildQueryKey(httpPath, method), { method }]; + const mutationKey = `['${method.name.value}']`; yield `export function ${name}(${optionsExpression}) {`; yield ` const queryClient = ${useQueryClient()}();`; yield ` const ${serviceName} = ${this.context.fn(serviceHookName)}()`;