I am creating a todo app in which :
-
a user can have many todos
-
and a todo can have a single user or owner
my schema is :
enum Priority {
P1
P2
P3
P4
}
type User {
name: String!
email: String! @unique
password: String!
todos: [Todo!] @relation
}
input UserInput {
name: String!
email: String! @unique
password: String!
todos: UserTodosRelation
}
type Todo {
todo: String!
description: String!
status: Boolean!
date: String!
priority: Priority
uid: ID!
subtodos: [Todo!]
comments: [String!]
reminders: [String!]
owner: User!
}
input TodoInput {
todo: String!
description: String!
status: Boolean!
date: String!
priority: Priority
uid: ID!
subtodos: [TodoInput!]
comments: [String!]
reminders: [String!]
owner: TodoUserRelation
}
input UserTodosRelation {
create: [TodoInput]
connect: [ID]
disconnect: [ID]
}
input TodoUserRelation {
create: UserInput
connect: ID
disconnect: Boolean
}
type Query {
allTodos: [Todo!]!
findTodoByUid(uid: ID!): Todo!
userExists(email: String!): Boolean! @resolver(name: "userExists")
userByEmail(email: String!): User! @resolver(name: "userByEmail")
}
type Mutation {
createSubTodo(parentId: ID!, newData: TodoInput!): Todo!
@resolver(name: "create_sub_todo")
updateRemindersList(todoUid: ID!, reminder: String!): String!
@resolver(name: "updateRemindersList")
deleteTodo(id: ID!, parentId: ID): Todo! @resolver(name: "deleteTodo")
}
now when I create a todo I want it to connect to a user using ID
my grapgql mutation :
mutation {
createTodo(data: {
todo: "test"
description: ""
status: false
uid: "0.157486448458"
priority: P4
date: "2021-03-23T14:07:17.851Z"
owner: {connect: 295406427520893447}
}) {
todo
owner {
name
email
}
}
}
but it returns an error :
{
"errors": [
{
"message": "Ref or Set expected, Object provided.",
"extensions": {
"code": "invalid argument"
}
}
]
}
I don’t know what is the problem and where I am going wrong.