Updating a database after an API service call

I guess I’m trying to figure out if mutations are only used on the front-end

Yes, sort of!

The flow would be

  1. Mutation getSomeData {} . Make sure the mutation is defined in the relevant sdl file, so your API side knows how to handle it.
  2. This would invoke your resolver for your mutation in your service
export const getSomeData = () => {
const exeternalData = await fetch('https://api.bazinga.kittens')

return db.table.update({
// .... use your exeternal data here
})
}

Bonus:
If you want to be fancy, you can also make use of caching using Service Caching or GraphQL caching

1 Like