Hello, I've started using Prisma and I have a rath...
# orm-help
c
Hello, I've started using Prisma and I have a rather dumb question. Following this example:
Copy code
type Human {
  id: ID! @unique
  brain: Brain
}

type Brain {
  id: ID! @unique
  human: Human!
}
This is an optional one-to-one relation, how should I check the existence of this relation from Human perspective ? I did:
Copy code
const brain = await prisma.human({ id }).brain()    
if (!brain) { ... }
But the typing is not correct,
brain
is of type
Brain
, and not
Brain | undefined
Am I doing something wrong ? Thanks 😃
l
That looks like an error from your server, not Prisma. How are you generating your types? If it's
graphqlgen
, try regenerating the types, especially if you recently changed the schema to allow humans to not have brains. đŸ€Ł
đŸ€Ł 1
c
I use Prisma CLI,
prisma generate
to generate TypeScript client
l
So is your server not running Typescript?
c
I use VSCode, and restarted TS server already
The problem looks like
.brain()
returns a
BrainPromise
, extends the
Promise<Brain>
type
l
Have you looked at the types file to make sure
brain: Brain | undefined
?
c
Types file looks incorrect indeed
I feeling like I am hitting a bug tbh
l
It could be, and not uncommon. Can you post the Human type?
c
Copy code
export interface HumanPromise extends Promise<Human>, Fragmentable {
  id: () => Promise<ID_Output>;
  brain: <T = BrainPromise>() => T;
}
^ return type of
.human(...)
Copy code
export interface Human {
  id: ID_Output;
}
l
So it looks like it's not generating a brain field
I know this is frowned on by the "gurus" in their TS towers, but when I encounter something like this and it takes me more than 5 minutes, I cast it to
any
and leave a note to revisit it in two weeks. Normally by then the bug works itself out
c
Looks like a reasonable solution
I am gonna raise a bug
@lawjolla Thanks for your time
💯 1
s
@divyendu can you take a look here? 🙂
d
Hey, it looks like you are running into this issue: https://github.com/prisma/prisma/issues/3774 I will get this validated and get back to you later.
c
👍
d
This indeed looks like a bug, please track the same GH issue for a resolution 👍
c
Thanks @divyendu