Prisma1: Document still being created even there is an error

Created on 17 Dec 2018  路  4Comments  路  Source: prisma/prisma1

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.

kinfeature areconnectomongo

Most helpful comment

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

All 4 comments

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.

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.

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MitkoTschimev picture MitkoTschimev  路  3Comments

thomaswright picture thomaswright  路  3Comments

dohomi picture dohomi  路  3Comments

sorenbs picture sorenbs  路  3Comments

hoodsy picture hoodsy  路  3Comments