我一直在玩“graphql-request”,我喜欢它,因为它很简单。有没有办法从我的请求中返回 http 状态代码?目前以下不起作用(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); });
文档不包括返回状态代码。希望这是可能的。谢谢。
你不能,现在写的方式。
仅在发生网络错误时才返回状态代码。如果您查看此包的源代码,您可以看到状态代码未在 上返回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#L34但是,没有什么可以阻止您创建项目并将状态代码添加到data
对象中。你甚至可以为项目做一个 PR。也许他们会合并它:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句