const resolver= {
Query: {
EventsQuery: async () => {
return await db.select('*').from('events')
},
},
Mutation: {
AddEventMutation: async (_: any, input) => {
return await db('events').returning('event_name').insert([
{
event_name: input.event_name,
event_venue: input.event_venue
}
]).then((name) => {
console.log(name) // value is displayed
return name
})
},
},
}
I have a GraphQL server that connects to the PostgreSQL DB and I am performing an INSERT SQL to add item in to the db. I am using Knex.js query builder and the above query inserts data into the table and returns event_name
. Data was inserted into the db but in GraphiQL I am getting this response. I think it should return a value instead of null.
{
"data": {
"AddEventMutation": {
"event_name": null
}
}
}
This is how I added the data into the db from GraphiQL.
mutation{
AddEventMutation(event_name: "Mutation", event_date: "1002") {
event_name
}
}
Can anyone tell me what went wrong? If getting the null value is correct, how does the client know if the mutation operation is a success or not? I am still experimenting and confused.