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] allow post with empty body #217

Closed
gunzip opened this issue Jun 24, 2019 · 6 comments
Closed

[feature request] allow post with empty body #217

gunzip opened this issue Jun 24, 2019 · 6 comments

Comments

@gunzip
Copy link

gunzip commented Jun 24, 2019

Expected Behavior

Mutations (PUT, POST) with empty body should be sent to the rest endpoint

Actual Behavior

Actually the client refuses to POST a request with an empty body

@fbartho
Copy link
Collaborator

fbartho commented Jul 18, 2019

We noticed in the beginning of apollo-link-rest that because it's a bit complicated to configure the body payload, people often accidentally sent bodies with empty payloads.

Do you have any advice, @gunzip, on how we could change this library to better support this feature, while still being safe for newbies? Maybe a magic value? or a new attribute on @rest(…) -- Note: I'd very much prefer not to add a new attribute unless we can't think of a better way to do it.

@gunzip
Copy link
Author

gunzip commented Jul 20, 2019

something like variables: { body: "" } would suffice. actually I have to setup a custom serializer to do that:

const restLink = new RestLink({
  uri: GATSBY_BACKEND_ENDPOINT,
  bodySerializers: {
    Json: (data: any, headers: Headers) => {
      return {
        body: data,
        headers: { ...headers, "Content-Type": "application/json" }
      };
    },
}

@fbartho
Copy link
Collaborator

fbartho commented Jul 20, 2019

Oh! That sounds like a great way to do it! Do you think it’s good enough? If so, we could document this as a recipe?

@gunzip
Copy link
Author

gunzip commented Jul 22, 2019

Well, if I can do this without a custom serializer (ie. body = "" supported directly into the client) I think that would be a nice addition to apolographql

@fbartho
Copy link
Collaborator

fbartho commented Jan 5, 2022

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

@fbartho
Copy link
Collaborator

fbartho commented Jan 5, 2022

Duplicates #198, closing.

@fbartho fbartho closed this as completed Jan 5, 2022
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

2 participants