0

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.

1 Answer 1

1

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:

However, 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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.