Apollo-server: RESTDataSource delete method doesn't accept body param

Created on 27 Aug 2018  路  5Comments  路  Source: apollographql/apollo-server

https://github.com/apollographql/apollo-server/blob/master/packages/apollo-datasource-rest/src/RESTDataSource.ts#L180
this method doesn't have body param to pas to request. could you add it? there's no reason to not support it because delete request supports it:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE

I know that the use of it is not recommended, but it's it's not prohibited either. and we're dealing with API that is using this kind of thing.

also, fetch method is private. so if any of the provided methods doesn't suit our needs, we're blocked from using this class.
https://github.com/apollographql/apollo-server/blob/master/packages/apollo-datasource-rest/src/RESTDataSource.ts#L190
also other methods (like post, put or patch) doesn't accept params property. so I don't understand why you're limiting other methods only to body params.

Apollo version: 2

馃К data-sources

Most helpful comment

We are running into this issue with our GraphQL server. We've been successfully able to work around it with above mentioned workaround, but it makes us very nervous to rely on something like this for a destructive operation. Would love official support.

All 5 comments

so no one is going to look into it?

Hi @edmundas-ramanauskas

I've succesfully use the third parameter init to set reqeust body on DELETE methods like this:

await this.delete(
  `/api/foo`,
  null,
  {
    body: { key: 'value'},
  }
);

@tw0517tw is this still working for you? It's not working for me... Body is empty on API side. If I call the API using Postman I can successfully pass and receive a body. So, something is happening between I call this.delete() and it gets to the server.

Here is how I'm calling it:

return this.delete(
  `/path/to/api`,
  undefined,
  {
    body: JSON.stringfy(myList),
  }
);

We are running into this issue with our GraphQL server. We've been successfully able to work around it with above mentioned workaround, but it makes us very nervous to rely on something like this for a destructive operation. Would love official support.

I got around this by using some code I found in another issue about arrays in the body (which has been fixed).

return this.delete('/path/to/api', JSON.stringify(list), { headers: { 'Content-Type': 'application/json' } });

Ugly but it works. As this issue is two years old I suppose it'll have to do.

Was this page helpful?
0 / 5 - 0 ratings