hi all, i have a todo and a tags table, i have a r...
# prisma-whats-new
u
hi all, i have a todo and a tags table, i have a relation many to many between them and i try to create a todo and set my tag with their ids, this is my mutation: mutation createTodo($text: String!, $ids: [ID!]) { createTodo (text: $text, tagsIds: $ids) { id text } } when creating todo from my app the tagsIds stay empty i dont know why i pass it like this : ["id1", "id2", ... , "idn"]
n
@uzu can you change it to
$ids: [ID!]!
and see what happens?
also, could you post the code where you set the variables and send the mutation?
u
handleSubmit(e) { e.preventDefault() this.props.form.validateFields((err, values) => { console.log(values.select); this.props.createTodo(values.text, values.select) }) this.props.form.resetFields(); }
n
doesn't look like you're providing the id variables
oh, sorry forget that
u
i query the tags table and construct my select multiple with it
n
what's the value of
values.select
?
u
["cj1c1691gtrct0186axr9h3oc", "cj1c16usftsbb0186lefiihwc", "cj1c1jtjwp3jj0178nsigpljf"]
when i change to $ids: [ID!]! i got this error :
Error: GraphQL error: Variable '$ids' expected value of type '[ID!]!' but value is undefined.
apparently my select mutliple doesnt works
this is strange
n
this means that
values.select
is
undefined
.
u
but i log it before this.props.createTodo and it isnt
i will investigate ... ty for the reply
n
hm
I might remember wrongly, but don't you need to pass a
variables
object to the mutation with the keys
text
and
ids
?
yea I'm pretty sure
u
in my export default i have the following syntax : graphql(createTodo, { props: ({ mutate }) => ({ createTodo: (text, select) => mutate({ variables: { text, select } }) .then((res) => { console.log("createTodo Success"); }) .catch((err) => { console.log(err); }) }) }),
so i suppose i dont have to pass a variables object to the mutation
Error: GraphQL error: Variable '$text' expected value of type 'String!' but got: {"variables":{"text":"test create","ids":["cj1c1691gtrct0186axr9h3oc","cj1c16usftsbb0186lefiihwc","cj1c1jtjwp3jj0178nsigpljf"]}}
n
change
createTodo: (text, select) => mutate({ variables: { text, select } })
to
createTodo: (text, ids) => mutate({ variables: { text, ids } })
u
oops
that was awkward for me ^^
ty
n
no worries 🙂