Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dongtanhuy opened this issue Mar 24, 2019 · 4 comments

Comments

@dongtanhuy
Copy link

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!

@fbartho
Copy link
Collaborator

fbartho commented Apr 15, 2019

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

@cloudever
Copy link

cloudever commented Apr 29, 2019

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

@fbartho
Copy link
Collaborator

fbartho commented Jun 14, 2019

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

@fbartho fbartho changed the title Empty request body from Mutation with PUT and POST method [Feature Request]: Empty request body from Mutation with PUT and POST method Jan 5, 2022
@fbartho
Copy link
Collaborator

fbartho commented Jan 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants