prisma1
prisma1 copied to clipboard
Document still being created even there is an error
Describe the bug In connect field, for example, an "id" field is required in connect. Even the id is invalid, the document (MongoDB) is still being created and return a null object. I also set non-null value for return values.
To Reproduce
mutation {
createCompany(data: {
name: "example company"
admin: {
connect: {
id: "invalid_id"
}
}
}) {
id
name
}
}
Expected behavior admin is required field when creating. Since admin.connect.id is invalid for ID type, the document should not be created
Versions (please complete the following information):
prismaprisma/1.22.2 (darwin-x64) node-v10.14.2
prisma-binding and client have the same issues.
Hi @soqt,
I am unable to reproduce the bug. Can you please provide the datamodel you are using. I used the following datamodel to reproduce this:
type User {
id: ID! @id
name: String
companies: [Company!]! @relation(link: INLINE)
}
type Company {
id: ID! @id
name: String
user: User!
}
Using this it threw the correct error when I provided it with the wrong id:

It will be great if you can provide a git repo with a minimal reproduction of this so that we can fix this issue.
Hi @pantharshit00,
type Company @db(name: "companies") {
id: ID! @id
name: String!
admin: User! @relation(name: "CompanyToAdmin" link: INLINE)
members: [User!]! @relation(name: "CompanyMembers")
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type User @db(name: "users") {
id: ID! @id
name: String
adminOf: Company @relation(name: "CompanyToAdmin")
company: Company @relation(name: "CompanyMembers" link: INLINE)
}
Here is the database.prisma type I used. Company["admin"] field is required when a user creates a company.

But if you now check out mongoDB, you will find a company document is created with empty "admin" field.
I'm not sure is that an expecting result since create and connect are two atom operations. But it make sense to not creating a document if one required field is invalid.
Currently there is no support for multi document transactions available for the Mongo connector which is why this is succeeding. Starting in Mongo 4.0 this is available, which is why we'll be able to add this at some point. But for now this is expected behaviour since we are running against Mongo 3.6 by default.
Hello, is there any idea on when this capability will be available in Prisma?