我正在用 Node.js 和 Express 编写一个 GraphQL 服务器。我有一个 JSON 数据文件,因此我使用 Axios 从该 JSON 文件中查询数据并将其传递给 GraphQL 查询,
const RootQuery = new GraphQLObjectType({
name:'RootQueryType',
fields: {
holiday: {
type: Holiday,
args:{
date:{type:GraphQLString},
},
resolve(parentValue, args) {
return axios.get('http://localhost:3000/holidays?date='+ args.date).then(res => res.data);
}
},
在 上console.log(res.data)
,我正在获取数据,但是,在从 GraphiQL 按日期查询时,我得到了
{
"data": {
"holiday": {
"holiday": null
}
}
}