hayes / pothos

Pothos GraphQL is library for creating GraphQL schemas in typescript using a strongly typed code first approach
https://pothos-graphql.dev
ISC License
2.28k stars 153 forks source link

Indirect prisma relations has type errors. #1184

Open charleslai2000 opened 2 months ago

charleslai2000 commented 2 months ago

When upgrade to 3.64.0 of @pothos/plugin-prisma, typescript report a type error for every indirect relations. A sample code is below:


export const ConceptNode = builder.prismaNode('Concept', {
  description: 'Concept information',
  // https://pothos-graphql.dev/docs/plugins/prisma#select-mode-for-types
  select: { id: true },
  // https://pothos-graphql.dev/docs/plugins/prisma#prismanode
  id: { field: 'id' },
  fields: t => ({
    version: t.exposeString('version', { description: 'Concept version' }),
    type: t.expose('type', {
      description: 'Concept type',
      type: ConceptCategoryEnum,
    }),
    name: t.exposeString('name', { description: 'Concept name' }),
    abbreviation: t.exposeString('abbreviation', { description: 'Concept abbreviation' }),
    description: t.exposeString('description', { description: 'Concept description' }),
    // https://pothos-graphql.dev/docs/plugins/prisma#indirect-relations-eg-join-tables
    superiors: t.field({
      description: 'Superior concepts',
      select: (args, ctx, nestedSelection) => ({
        superiors: {
          select: {
            superior: nestedSelection(true),
          },
        },
      }),
      type: [ConceptNode],
      resolve: concept => concept.superiors.map(({ superior }) => superior),
    }),
  }),
})

The select field of superiors field report error: Type '{ superiors: { select: { superior: true; }; }; }' is not assignable to type 'never'.ts(2322)

Please check this. My whole project can not compile now.

hayes commented 2 months ago

Have you rerun Prisma generate after upgrading?

charleslai2000 commented 2 months ago

Yes, I have re-run the generate command.

hayes commented 2 months ago

I haven't been able to replicate this in any of the repos I have that use the Prisma plugin. Is there a reproduction you might be able to share?