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

Implemented on #256 UpdateOperationsInput Type Generation Disabled #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

StringKe
Copy link

@StringKe StringKe commented May 31, 2024

The types of SomeUpdateArgsSchema do not use the where condition of methods such as find.

    update: adminProcedure.input(ProductAttributeUpdateArgsSchema).mutation(async ({ input }) => {
        const database = getDatabase();

        if (!input.where.id) {
            throw BusinessError.fromCode('ID_NOT_FOUND');
        }

        const data = await database.productAttribute.findUnique({
            where: {
                id: input.where.id, // SomeUpdateArgsSchema not worker this
            },
        });

        if (!data) {
            throw BusinessError.fromCode('ID_NOT_FOUND');
        }

        return database.productAttribute.update({
            where: {
                id: input.where.id,
            },
            data: input.data,
        });
    }),

@StringKe StringKe changed the title #256 Implemented on #256 UpdateOperationsInput Type Generation Disabled Implemented on #256 UpdateOperationsInput Type Generation Disabled May 31, 2024
@chrishoermann
Copy link
Owner

Hey @StringKe thanks for the pr.

in your example above you describe that the SomeUpdateArgsSchema does not use the where condition of SomeFindUniqueArgsSchema, which would be SomeWhereUniqueInputSchema, but actually it does - at least in my generated schemas.

From the code example I assume you want to have the input.where.id field to be mandatory. There seems to be an issue in my implementation of the generated whereUniqueInputSchema.
Prisma uses the AtLeast type, that ensures, that at least the provided unique field is used in the query, but my implementation currently does not reflect that because the mandatory id field gets overwritten by the optional id field like in this example

export const ModelWithOptionsWhereUniqueInputSchema: z.ZodType<Prisma.ModelWithOptionsWhereUniqueInput> = z.object({
  id: z.number().int()
})
.and(z.object({
  id: z.number().int().optional(),
  AND: z.union([ z.lazy(() => ModelWithOptionsWhereInputSchema),z.lazy(() => ModelWithOptionsWhereInputSchema).array() ]).optional(),
  OR: z.lazy(() => ModelWithOptionsWhereInputSchema).array().optional(),
  NOT: z.union([ z.lazy(() => ModelWithOptionsWhereInputSchema),z.lazy(() => ModelWithOptionsWhereInputSchema).array() ]).optional(),
  string: z.union([ z.lazy(() => StringFilterSchema),z.string() ]).optional(),
}).strict());

This schema should reflect the type

  export type ModelWithOptionsWhereUniqueInput = Prisma.AtLeast<{
    id?: number
    AND?: ModelWithOptionsWhereInput | ModelWithOptionsWhereInput[]
    OR?: ModelWithOptionsWhereInput[]
    NOT?: ModelWithOptionsWhereInput | ModelWithOptionsWhereInput[]
    string?: StringFilter<"ModelWithOptions"> | string
  }, "id">

where at least the id field should be mandatory.

so this should have to do nothing with the UpdateOperationsInput like in your PR. Or did you have some other things in mind with the optionality of the UpdateOperationsInput?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants