paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

Use custom resolver when nexus-plugin-prisma generate types #157

Closed leoDreamer closed 3 years ago

leoDreamer commented 3 years ago

Hi, in nexus-plugin-prisma options, we can replace the default resolve,there are any solution to use custom resolver in some t.crud image

AhmedElywa commented 3 years ago

@leoDreamer You can generate your CRUD just one time with my CLI and update it.

Don't forget if you rerun; the CLI will replace your work

leoDreamer commented 3 years ago

@AhmedElywa thanks reply. because of rerun will replace my custom code, I couldn't update the generated CRUD, there are any plan to support nexus-plugin-prisma option in CLI

AhmedElywa commented 3 years ago

Can you suggest how we can support this option? Thanks

leoDreamer commented 3 years ago

How about this, in CLI option define like

customResolverByModel: {[modelName: string]: {[fieldName: string]: function}[]}

use like

customResolverByModel: {
  User: [
    { findOne: async function(root, args, ctx, info, originalResolve) {...} },
    // or
    { findMany: require(path.join(process.cwd(),'src/resovler/user')).findMany },
  ]
}

write the fieldName's value to the generated code as nexus-plugin-prisma's option

AhmedElywa commented 3 years ago

Yes, this can be an option, but I will take the function as a string like this.

customResolverByModel: {
  User: [
    { findOne: `async function(root, args, ctx, info, originalResolve) {...}`},
  ]
}

because we print this code in your files, not use as a function

leoDreamer commented 3 years ago

Thanks a lot,look forward to this feature publish.

AhmedElywa commented 3 years ago

@leoDreamer when I was working on this. I said we already have a nexus generator that generates native nexus types without using nexus-plugin-prisma. If you need to customize everything, why use nexus-plugin-prisma instead of nexus generator. Can you give this a try?.