prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

Document still being created even there is an error

Open soqt opened this issue 6 years ago • 4 comments
trafficstars

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):

  • prisma prisma/1.22.2 (darwin-x64) node-v10.14.2

prisma-binding and client have the same issues.

soqt avatar Dec 17 '18 10:12 soqt

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: image

It will be great if you can provide a git repo with a minimal reproduction of this so that we can fix this issue.

pantharshit00 avatar Dec 17 '18 16:12 pantharshit00

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. screen shot 2018-12-18 at 10 46 05 am

But if you now check out mongoDB, you will find a company document is created with empty "admin" field.

screen shot 2018-12-18 at 10 47 55 am

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.

soqt avatar Dec 18 '18 02:12 soqt

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.

do4gr avatar Jan 02 '19 12:01 do4gr

Hello, is there any idea on when this capability will be available in Prisma?

xcdt avatar Aug 14 '19 09:08 xcdt