[resolved] problem with .sdl generator

I am having trouble with the type support?

given this schema

model Agreement {
  id         String             @id
  attendees  Attendee[]
  businesses BusinessPurchase[]
}

the output .sdl is right

  type Agreement {
    id: String!
    attendees: [Attendee]!
    businesses: [BusinessPurchase]!
  }

but typescript complains that the service constructor is off

Property ‘attendee’ does not exist on type ‘Prisma__AgreementClient’. Did you mean ‘Attendee’?

Property ‘businessPurchase’ does not exist on type ‘Prisma__AgreementClient’. Did you mean ‘BusinessPurchase’?

export const Agreement = {
  attendees: (_obj, { root }: ResolverArgs<ReturnType<typeof agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).attendees(), 
  businesses: (_obj, { root }: ResolverArgs<ReturnType<typeof agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).businesses(),
}

I have to correct it to this to get the types to be happy

export const Agreement = {
  attendees: (_obj, { root }: ResolverArgs<ReturnType<typeof agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).Attendee(),
  businesses: (_obj, { root }: ResolverArgs<ReturnType<typeof agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).BusinessPurchase(),
}

The old .35 constructor generation is nearly the same as the new .38 but doesn’t complain…

export const Agreement = {
  attendees: (_obj, { root }: ResolverArgs<ReturnType<typeof Agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).attendees(),
  businesses: (_obj, { root }: ResolverArgs<ReturnType<typeof Agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).businesses(),
};

I don’t know why the .35 was checking the type of Agreement, while the new .38 checks the type of agreement. Typing in the .38 doesn’t seem to care either way…

Am I missing something?

Hey @ajoslin103, would you be able to share your full schema so we can reproduce this bug?

@rob and I had a look and it seems to us that the generated code and types are correct (even if a little convoluted)

Thanks!

(apparently I had not hit ‘send’ on this draft)

with this schema

model Agreement {
  id         String             @id
  attendees  Attendee[]
  businesses BusinessPurchase[]
}

and this .sdl

  type Agreement {
    id: String!
    attendees: [Attendee]!
    businesses: [BusinessPurchase]!
  }

and this service Constructor

export const Agreement = {
  attendees: (_obj, { root }: ResolverArgs<ReturnType<typeof agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).attendees(),
  businesses: (_obj, { root }: ResolverArgs<ReturnType<typeof agreement>>) =>
    db.agreement.findUnique({ where: { id: root.id } }).businesses(),
}

typescript is happy…

Ha! Convolution is my middle name !! I regularly program myself into corners and then must awaken my inner contortionist to escape !

As I continued on with the problem it became more clear that most of the issues were from be doing a prisma db pull on the database from the new project and then NOT going in and fixing the variable names

The pull had created [pascal case] names corresponding to the entity names (because it didn’t have the local naming from the old project) which is what had confused me so much.

I’ve been back and forth through the looking glass lately as the project ended up splitting into two codebases because one set of users needed authentication via phone number and the others need to authenticate via email. As long as I sync the migrations folders and the schema files I’ve managed to avoid shooting my foot completely off.

At least I’ve tentatively proven that it works to share databases between projects if you’re careful.

Thanks!