Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
102 stars 19 forks source link

Add simple mode to input generator #30

Closed quintal-william closed 1 year ago

quintal-william commented 1 year ago

This PR adds a "simple" mode to the input generation that uses unchecked inputs to:

All without losing much of the expressiveness of the GraphQL API.

Simple mode is enabled by setting config.inputs.simple to true, it is false by default since that would be a breaking change.

I'm testing this mode out on a personal project, I will report back to see if it is actually functioning as planned. In the meantime I'd love to hear your thoughts!

quintal-william commented 1 year ago

After our conversation I will remove the exports I had added back in from this PR 👌🏼

Cauen commented 1 year ago

Hi @saphewilliam Tested and It seems to be great ✔ Inputs really got simpler and easier to use 🚀

I will report back to see if it is actually functioning as planned.

Its ready for merge?

quintal-william commented 1 year ago

I'm testing it this weekend / next week, then I'll be sure if it's ready 😄

quintal-william commented 1 year ago

I've tested the simple mode on a project of mine and it seems to work perfectly now! @Cauen Could you merge this PR and update the package in npm? 😄

quintal-william commented 1 year ago

Would be nice to have some sort of auto-publishing setup using Changesets in a github action

Cauen commented 1 year ago

@saphewilliam It seems like using PrismaUpdateOperationsInputFilter is removing type safety from args

export const PostCreateInput = builder.inputRef<PrismaUpdateOperationsInputFilter<Prisma.PostCreateInput>>('PostCreateInput').implement({
  fields: PostCreateInputFields,
});

image

Would be nice to have some sort of auto-publishing setup using Changesets in a github action

Thats great, i'll take a look


Edit:

Seems like its used in all inputs, but its done for update inputs only What is the point of this generic?

quintal-william commented 1 year ago

@Cauen

What is the point of this generic?

TL;DR

It matches the internal prisma type with the generated graphql endpoint.

Long answer

The GraphQL schema generated from our code: image

However, the Prisma schema also allows raw string inputs: image

The generic strips away the raw string input to reflect the GraphQL schema better. Not doing this gave me some issues when trying to extend the generated code

image Even though "set" is the only available option, I can't easily access it without doing a useless check if the arg is a string, it is in fact never a string.

This is that same code with the generic added: image

Your issue

I can't seem to reproduce your issue? It works fine for me image image

quintal-william commented 1 year ago

Also I did it for all inputs because it's just easier and I thought it didn't have any effect on the other inputs.

Cauen commented 1 year ago

@saphewilliam Thanks for answer, looks very useful

About args, have you tried with the example in repo? image It shows all properties, But almost everything is "any" image Its seems like a version missmatch, what is you version configs?

quintal-william commented 1 year ago

You're right, I think the prisma client is generating them only if necessary, so if the bool one is not used, it is not generated. Great catch! I'll fix this bug with a bit more sophisticated checking in the generic type.

quintal-william commented 1 year ago

I made a new generic type that should fix this issue, could you test it on your setup just to be sure? 😄

Cauen commented 1 year ago

Awesome