One-To-Many relation throws error after second record

framework

#1

Hey guys, i’am working on a project where a user can create a group - the target is that i can list all groups the account created, so i’ve a typical 1:n relation.

But, and i really have no idea why, i always get this message when i create as a user the second group (so creating the first group is fine)

A unique constraint would be violated on Group. Details: Sorry, no more details available.

This is my mutation in my react project, i want to create a group and assign the actual user as owner (createdBy)

const createGroup = gql`
  mutation createGroup($title: String!, $auth0UserId: String!) {
    createGroup(
      title: $title,
      createdBy: {
        auth0UserId: $auth0UserId
      }
    ) {
      id
    }
  }
`

And here are my graph-types:

type Group @model {
  id: ID! @isUnique
  title: String!
  createdAt: DateTime!
  updatedAt: DateTime!
  user: User @relation(name: "UserGroup")
}

type User @model {
  id: ID! @isUnique
  auth0UserId: String @isUnique
  email: String
  createdAt: DateTime!
  updatedAt: DateTime!
  groups: [Group!]! @relation(name: "UserGroup")
}

My local graphcool version is
graphcool-framework/0.11.5 (darwin-x64) node-v8.1.2

For test cases i’am currently using the graph-cool servers (so non-local)


#2

Ok guys, just asking, noticed i’am using graph-cool (cli) and not prisma… is that the problem? Oo


#3

Hey @mzio,

    createGroup(
      title: $title,
      createdBy: {
        auth0UserId: $auth0UserId
      }
    )

Creates a group and a user every single time it’s executed. So, the second time it fails because of the unique constraints on auth0UserId. The error message is misleading.

If you’re just getting started, you can look into Prisma. There, upserts are supported so you can tackle this specific case more elegantly.


#4

The following way that will be going to proceed it in such way that it will be applicable to manage it in such way where iphone repair dubai it is going to it for manner where need to know why one to many relation throws error after second record that specific elegantly.