-
Notifications
You must be signed in to change notification settings - Fork 11
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
Caching issue with MutationWithZod #22
Comments
Hello @binhnc1991 ! When I see the underlying issue and fix it if there was a problem, I'll notify you here about the fix. |
Hello, I am getting this issue now too. Just want to keep it on your radar - i might look into the code soon as well as it is a big issue for us. happens on my @query with the input. here is what i have @Query(() => [DateMetricData])
async getMetrics(
@CurrentUser() id: string,
@Args('input') input: GetMetricDataInput
): Promise<DateMetricData[]> {
input.userId = id;
return await this._numberKeeperService.getMetrics(input);
} @InputType()
export abstract class GetMetricDataInput extends inputFromZod(
GetMetricDataSchema
) {
constructor() {
super();
}
} export const GetMetricDataSchema = z.object({
all: z.boolean().optional(),
date: z.string().optional(),
// dateEnd: z.string().optional(),
// dateStart: z.string().optional(),
id: z.string().optional(),
metricTime: z.enum([
MetricTime.quarter,
MetricTime.day,
MetricTime.week,
MetricTime.all
]),
metricType: z.enum([
MetricType.all,
MetricType.rock,
MetricType.brick,
MetricType.dailyNumber
]),
userId: z.string().optional()
}); if i should be doing this another way, please let me know. |
Environment:
Description:
I have encountered a caching issue when utilizing the
MutationWithZod
decorator from "nestjs-graphql-zod" library. Despite having server caching disabled in my project, there seems to be an issue with caching. Here's a brief overview of the scenario:Upon the first invocation of the GraphQL mutation, the
fieldB
value is correctly included in the GraphQL response. However, in subsequent calls, if the returned result fromtestFunction
lacksfieldB
(e.g., only{ fieldA: true }
is returned), the previous value offieldB
is unexpectedly preserved. That means, the value of an optional field persists even when not included in the latest response.Expected Behavior: It should not retain the value of any optional field if it is not present in the subsequent GraphQL mutation responses.
FYI, a workaround that uses
modelFromZod
Using this workaround eliminates the caching problem, and the behavior aligns with the expected outcome.
Thank you
The text was updated successfully, but these errors were encountered: