graphql-schema-generator-rest
graphql-schema-generator-rest copied to clipboard
`errors` mapper for server response
I've realized I have no way to resolve error of server response, looks like this line ignored server error and did nothing. I expected that can be resolved to errors
of GraphQL response, is this lib have any plans to support or PR welcome? 😃
@jhen0409 Sure feel free to pitch your idea/file in a pull request. Error handling is important!
Hi,
I can’t speak for Laurin but I would welcome a PR that stops ignoring errors. In the meantime, you can provide a custom fetcher to generateRestSchema
. That custom fetcher could be something like:
const fetcher = (...args) => fetch(...args).then((response) => {
if (!response.ok) {
throw new Error('Network Error');
}
return response;
});
The thrown error will appear in the GraphQL response.
@jhen0409 @fodier We could call response.json()
either way, however some API do not include a response body when sending a 500 or 404 error (https://github.com/n1ru4l/graphql-schema-generator-rest/issues/32).
We could also change the behaviour of responseMapper
completely. When not declared everyting would behave like the current implementation. Otherwise the responseMapper
function receives the raw response
object returned by fetch
and the user has to determine whether it is an error by returning a Promise
that either resolves or rejects.
@jhen0409 @fodier what do you think?