5

I'm using GraphQL to connect to multiple RESTful endpoints. I'm writing a mutation to update user details, however GraphiQL is showing the following response of null rather than the updated user ID and name...

{
  "data": {
    "updateUser": null
  }
}
  updateUser: (parent, args) => {
    const { id, name } = args;
    return fetch(`${url}/users/${id}`, {
      method: 'PUT',
      body: JSON.stringify({ id, name }),
      headers: { 'Content-Type': 'application/json' },
    })
      .then(res => res.json())
      .then(json => console.log(json));
  },

Thanks in advance.

JS_Dev
  • 427
  • 4
  • 14

1 Answers1

2

You need to return your resolved json, otherwhise there is no returning value for the fetch call.

.then(json => json);

or if you want

.then(json => {
  console.log(json);
  return json;
});
U Rogel
  • 1,893
  • 15
  • 30