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.

2
  • Get rid of .then(json => console.log(json)). console.log has no return value. Commented Feb 4, 2019 at 20:58
  • Please see Common Scenario #5 in this answer. Commented Jun 1, 2019 at 15:23

1 Answer 1

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;
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.