Reputation: 143
I've been playing around with "graphql-request" and I like it because of it's simplicity. Is there any way of returning the http status code from my request also? Currently the following doesn't work (response.status):
const {request} = require('graphql-request');
const query = `{
Post(id: 1) {
id
title
views
User {
name
}
Comments {
date
body
}
}
}`;
request('http://localhost:3000', query)
.then(response => console.log(response.status))
.catch(err => { throw new Error(err); });
The Documentation doesn't cover returning status codes. Hopefully it's possible. Thanks.
Upvotes: 0
Views: 1302
Reputation: 5313
You can't, the way it's written now.
Status codes are only returned in the event of a network error. If you look at the source code for this package, you can see that a status code is not returned on Fetch#ok
:
request
: https://github.com/graphcool/graphql-request/blob/master/src/index.ts#L66rawRequest
: https://github.com/graphcool/graphql-request/blob/master/src/index.ts#L34However, there's nothing stopping you from forking the project and adding the status code to the data
object. You could even make a PR back to the project. Maybe they'll merge it :)
Upvotes: 1