apollo-link-rest icon indicating copy to clipboard operation
apollo-link-rest copied to clipboard

[Feature Request]: Empty request body from Mutation with PUT and POST method

Open dongtanhuy opened this issue 5 years ago • 4 comments

Hi development team, I am building an example using apollo-link-rest, when I use mutation to edit data, I realize that the request body was empty although I did add headers with: "Content-Type": "application/json", This is my actual code:

const withEditTodo = gql`
  mutation EditTodo($id: Int!,$text: String!) {
    editTodo(id: $id, text: $text)
      @rest(method: "PUT", type: "Todo", path: "/todos/:id", bodyKey: "text") {
      id
      text
      completed
    }
  }
`;
...
export default compose(
...
graphql(withEditTodo, {
    props: ({ mutate }) => ({
      editTodo: (id, text) =>
        mutate({
          variables: { id, text: { text } },
          refetchQueries: [{ query: withTodos }]
        })
    })
  }),
...
)(MyComponent)

I read all issues on Github and cannot find the solution. Can you give me some ideas to fix it? Thanks!

dongtanhuy avatar Mar 24 '19 13:03 dongtanhuy

I'm not super familiar with the graphql higher order component & it's usage with compose() Have you verified if the request actually got sent with the correct headers?

Your sample code doesn't show how you configured the Apollo Client

fbartho avatar Apr 15 '19 21:04 fbartho

An input variable for POST / PUT methods always should be object or array, so $text in your code can't be a string

cloudever avatar Apr 29 '19 15:04 cloudever

You may need to use a responseTransformer to achieve that particular body @dongtanhuy

fbartho avatar Jun 14 '19 21:06 fbartho

If somebody wants to implement this, we can take a look.

fbartho avatar Jan 05 '22 22:01 fbartho