Error generating schema for Graphql with Graphcool

Asked

Viewed 41 times

0

I am trying to create a Schema with Graphcool in an Angular application. The types are as follows::

type User @model {
  id: ID! @isUnique
  name: String!
  email: String! @isUnique
  password: String!
  createdAt: DateTime!
  updatedAt: DateTime!
  chats: [Chat!]! @relation(name: "UsersOnChats")
  messages: [Message!]! @relation(name: "MessagesOnUser")
  photo: File @relation(name: "UserPhoto")
}

type Chat @model {
  id: ID! @isUnique
  title: String
  isGroup: Boolean @defaultValue(value: "false")
  createdAt: DateTime!
  updatedAt: DateTime!
  users: [User!]! @relation(name: "UsersOnChats")
  messages: [Message!]! @relation(name: "MessagesOnChat")
  photo: File @relation(name: "ChatPhoto")
}

type Message @model {
  id: ID! @isUnique
  text: String!
  createdAt: DateTime!
  sender: User! @relation(name: "MessagesOnUser")
  chat: Chat! @relation(name: "MessagesOnChat")
}

type File @model {
  id: ID! @isUnique
  secret: String
  name: String
  size: Int
  url: String
  contentType: String
  user: User @relation(name: "UserPhoto")
  chat: Chat @relation(name: "ChatPhoto")
}

While running the application and trying to run the console to check my Mutation, I get the following error:

ERROR Error: "Graphql error: A Unique Constraint would be violated on User. Details: Field name = email"

1 answer

0

It seems to me that there is already a database created with these specifications and, there is an error that hurts the directive @isUnique in the field email of the model User. Check if there are no users already entered in the database with the same email.

You can even temporarily remove this directive, only to pass this step where the error occurs, and then check the contents of the database and finally make the appropriate changes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.