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
95 stars 16 forks source link

Bug while using deleteOne method #24

Closed pedrosimao closed 1 year ago

pedrosimao commented 1 year ago

I am using the library with Next.JS and all recommended library versions. I can create an object using createOneSomething mutation without any issue. But when i try to use deleteOneSomething I get this error:

"Cannot read properties of undefined (reading 'something')"

While inspecting the code I have noticed this line of code resolve: async (query, _root, args, _context, _info) => is passing undefined parameters.

Weirdly, both _context.prisma and args.where seem to be undefined. Even more weird when the same does not happen with the create method.

pedrosimao commented 1 year ago

Ok, I think I have an idea of where the bug comes from. I was using the autocrud functions like this:

generateAllObjects({ include: ['Something'] })
generateAllQueries({ include: ['Something'] })
generateAllMutations({ include: ['Something'] })

Then I decided to try to remove those and manually creating each query, mutation and object like this:

builder.prismaObject('Something', SomethingObject)
builder.mutationFields(deleteOneSomethingMutation)
builder.mutationFields(createOneSomethingMutation)
...

And this seems to have fixed the issue. I am not sure why, but I guess it is some issue with the autocrud ...

Cauen commented 1 year ago

@pedrosimao Thanks for your report This bug was introduced in the new autocrud implementation Just got fixed in version 0.5.2

Can you please check if this time is ok? :D