Simple mutual relationship in mutation , but can't figure out what I'm doing wrong, " Cannot return null for non-nullable field"

prisma

#1

Data Model:

 type User {
 id:ID! @id
 handle: String! @unique
 email: String! @unique
 organizations: [Org!]! @relation(name:"OrgsToUsers")
}

type Org {
  id:ID! @id
  members:[User!]! @relation(name:"OrgsToUsers")
  name: String! @unique
}

My latest attempt at seeding this model:

mutation {
  
user1: createUser(
data: {
  handle: "Pueblo" 
  email: "pueblo@pablo.net"
  organizations: {create : []}
}
  ) {
  id
  handle
  email
  organizations {
    name
  }
}

org1: createOrg(
data: {
  name: "Jara Inc." 
  members: { connect:  [{handle: "Pueblo", email: "pueblo@pablo.net"}] }
}
  ) {
  name
  members {
    handle
  }
}

  connectEm: updateUser(
where: {handle:"Pueblo"  }
data: {
  organizations: {
    connect: [{ name: "Jara Inc." }]
  }
}
  ) {
handle
id
organizations {
 name
}
  }
  
}

I’ve tried various combinations of connecting and creating these two, but I always end up with this error: Cannot return null for non-nullable field Org.members.

For any query I run that contains that field.

Any help would be much appreciated.


#2

Among the many other ways I’ve tried this this is one configuration:

mutation {
user1: createUser(
    data: {
      handle: "Pueblo" 
      email: "pueblo@pablo.net"
      organizations: {
        create: [{ name: "Jara Inc." }]
      }
    }
  ) {
      id
      handle
      email
      organizations {
        name
        members {
          handle
        }
      }
    }

org1: updateOrg(
    where: {
      name: "Jara Inc." 
    }
    data: {
      members: {
         connect: 
         {
           handle: "Pueblo"
         }
      }
    }
  ) {
      name
      members {
        handle
        organizations {
          name
        }
      }
    }

  connectEm: updateUser(
    where: { 
      handle: "Pueblo" 
      }
    data: {
      email:"newEmailThisUpdateWorks"
      organizations: {
        connect: { 
          name: "Jara Inc." 
          }
      }
    }
  ) {
    handle
    id
    organizations {
     name
     members {
       handle
     }
    }
  }
}

Though the last update works, the connections still render those fields as nulls.

Now I get this:

{
  "data": {
    "users": [
      {
        "email": "newEmailThisUpdateWorks",
        "handle": "Pueblo",
        "organizations": null
      }
    ],
    "orgs": [
      {

        "name": "Jara Inc.",
        "members": null
      }
    ]
  }
}

as a response for this

query {
  users {
     email
     handle
    organizations {
      id
    }
  }
  
  orgs {
    name
    members {
      id
    }
  }
}

This is driving me crazy, what am I doing wrong, am I missing something fundamental here?


#3

This may be relevant: https://github.com/prisma/prisma/issues/1984


#4

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.