apollo-link-rest
apollo-link-rest copied to clipboard
[Feature Request]: Empty request body from Mutation with PUT and POST method
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!
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
An input
variable for POST / PUT methods always should be object or array, so $text
in your code can't be a string
You may need to use a responseTransformer
to achieve that particular body @dongtanhuy
If somebody wants to implement this, we can take a look.