apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
https://www.apollographql.com/docs/apollo-server/
MIT License
13.79k stars 2.03k forks source link

apollo-datasource-rest doesn't understand application/problem+json mime type #4110

Closed davedx closed 4 years ago

davedx commented 4 years ago

In RESTDataSource.parseBody, it checks the media type of an API response as follows:

  (contentType.startsWith('application/json') ||
    contentType.startsWith('application/hal+json'))

However there is an additional JSON mime type used in for example ASP.NET core to return non-200 JSON responses called "application/problem+json". [1] If an API returns a response with this mime type, you'll end up with a plaintext response in your graphql server code instead of a JSON object.

It seems fairly straightforward that this type should just be added to the above check. I'll make a PR

[1] https://tools.ietf.org/html/rfc7807

abernix commented 4 years ago

See: