Hey folks, Would love some help with this non-desc...
# orm-help
d
Hey folks, Would love some help with this non-descriptive error message I'm getting (see screenshot). I call
prisma.query.create
as follows (where queryService(data) is just calling
prisma.create({data})
):
Copy code
const query = await this.queryService.createQuery({
            genome: s.slice(0,10),
            type: 'Auto',
            description: form.description,
            user: {
                connect: {id: user.id}
            }
        });
This produces the error pretty much no matter what I do. I logged the object I'm trying to insert, seems fine... so I don't see what the problem is. The relevant model is:
Copy code
model Query {
  id String @id @default(uuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  user User @relation(fields: [userId], references: [id])
  userId String

  genome String
  type GenomeType @default(Auto)
  description String?
  result String?
}
Would appreciate any help!
g
what if you escape the
>
character in the
genome
field?
d
It's sadly not that. I tried setting
genome: ''
earlier, and just did it again, no change.
Copy code
{
            genome: '',
            type: GenomeType.Auto,
            description: form.description,
            user: {
                connect: {id: user.id}
            }
}
j
Ugh that looks pretty bad.
Can you open an issue? Then it will be much easier for us to ask for the appropriate logs and other things we might need.
I am pretty sure something is going wrong with the "genome" value you are sending in, but it totally should not.
d
You bet. I just asked on here because I figured it was purely on my end, and would get a quicker response here. Yeah, the only relevant information is that it's a very, very long string. But it shoul dn't matter because it's using TEXT with pg... Also, I just migrated from MikroORM and this query was working fine there, so it seems to be something with how I'm making the request or how prisma is parsing it, not at the db level.
I actually solved it, pretty bizarre stuff! When I was posting the issue I figured I would rename it to BlastQuery incase Query conflicted with something else... That didn't fix it, but changed the error message to:
Copy code
Invalid `prisma.blastQuery.create()` invocation:


An operation failed because it depends on one or more records that were required but not found. No 'User' record(s) (needed to inline the relation on 'BlastQuery' record(s)) was found for a nested connect on one-to-many relation 'BlastQueryToUser'. +13253ms
Then I realized I accidentally did
const user = session
instead of
const {user} = session
, so I was looking up session uuid and not user uuid... what a classic screw up lol. I love coding, it's like you have all these complex problems and you troubleshoot in complex ways and then you find out you just forgot to destructure 😂
@janpio do you know why the logging behavior might've been different when it was named Query? I don't think I changed anything else... Or now I'm wondering if maybe the two issues are disconnected, and the GraphQL syntax parsing issue was caused by the "query" name... which could interfere with
query {}
in GQL. If this name conflict does exist, that's probably worth documenting somewhere, if even only in a troubleshooting section.
j
That is definitely a bug then, something we did not anticipate.
Can you open an issue for the
Query
thing? Maybe even with a smaller reproduction? As soon as you read about our internal GraphQL API you know something is really broken 😞
d
Sure, I will try and reproduce with something I can make open source that's nice and simple, and post an issue tonight once I'm off work. And rip... that bad? I'm pretty new to Prisma so haven't meddled much with internals. Speaking of which, while I have you, do you happen to know what the actual type is of an object with included relations using Prisma.validator? I couldn't find it. For example:
Copy code
getSessionData(id: string): Promise<Session | null> {
        const includeUsers = Prisma.validator<Prisma.SessionInclude>()({
            user: true
        });

        return this.prisma.session.findFirst({
            where: {id},
            include: includeUsers
        });
    }
Here,
Promise<Session | null>
is a lie, since it's actually
Session & {user: User}
...
j
Nope, super limited knowledge of that part so better ask in a separate thread or GH discussion.
I'm pretty new to Prisma so haven't meddled much with internals.
You should not even know that there is some GraphQL like thing under the hood 😄
d
Oops...
I finally got around to posting the issue: https://github.com/prisma/prisma/issues/8153 While I was at it, I posted another issue which I think should be fixed and/or documented: https://github.com/prisma/prisma/issues/8152 Was pretty busy last few days so took me a bit to get to this.
j
Thanks for these - will take a look and apply labels etc to get it into our process.