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 18 forks source link

Nexus-Prisma-like CRUD generation #7

Closed saphewilliam closed 2 years ago

saphewilliam commented 2 years ago

This is the second of two Pull Requests (previous: #6) implementing the desired nexus-prisma-like feature set as discussed in #4

This PR contains:

This PR does not contain:

saphewilliam commented 2 years ago

Still TODO: I think we should expose all object fields as their own objects aswell, which would allow for easy field modification

Current situation:

export const UserObject = definePrismaObject('User', {
  description: undefined,
  findUnique: ({ id }) => ({ id }),
  fields: (t) => ({
    id: t.exposeID('id', { description: '@Pothos.omit(create, update)', nullable: false }),
    createdAt: t.field({
      type: Inputs.DateTime,
      description: '@Pothos.omit(create, update)',
      nullable: false,
      resolve: (parent) => parent.createdAt,
    }),
  }),
});

Desired situation:

export const UserIdField = defineIdField({
  description: '@Pothos.omit(create, update)',
  nullable: false
});

export const UserCreatedAtField = defineField({
  type: Inputs.DateTime,
  description: '@Pothos.omit(create, update)',
  nullable: false,
  resolve: (parent) => parent.createdAt,
});

export const UserObject = definePrismaObject('User', {
  description: undefined,
  findUnique: ({ id }) => ({ id }),
  fields: (t) => ({
    id: t.exposeID('id', UserIdField),
    createdAt: t.field(UserCreatedAtField),
  }),
});
saphewilliam commented 2 years ago

Still TODO: I think we should expose all object fields as their own objects aswell, which would allow for easy field modification.

This is now resolved and added to documentation! IMO it's ready for review and merge.

Cauen commented 2 years ago

Hi @saphewilliam I'm really happy to see the improvements you've made here.

I tested it a few days ago, and I didn't have time to formulate a message about the improvements I was going to suggest. But you already made them