Axios 查询在Apollo运行时显示为空。我不确定这是冲突解决程序还是架构问题
我不确定我在这里做错了什么,但是当我在graphql上运行我的查询时,我总是得到null 这是我的解析器:Axios 查询在Apollo运行时显示为空。我不确定这是冲突解决程序还是架构问题,axios,schema,apollo,Axios,Schema,Apollo,我不确定我在这里做错了什么,但是当我在graphql上运行我的查询时,我总是得到null 这是我的解析器: Query: { getCountryData: (parent, args) => { return axios .get(`https://thevirustracker.com/free-api?countryTimeline=US`) .then((res) => { console.log(res
Query: {
getCountryData: (parent, args) => {
return axios
.get(`https://thevirustracker.com/free-api?countryTimeline=US`)
.then((res) => {
console.log(res.data);
res.data;
});
},
},
};
这是我的模式
gql`
extend type Query {
getCountryData: getCountryData
}
type getCountryData {
countrytimelinedata: [countrytimelinedata]
timelineitems: [TimelineItem]
}
type TimelineItem {
date: String!
new_daily_cases: String!
new_daily_deaths: String!
total_cases: String!
total_recoveries: String!
total_deaths: String!
}
type countrytimelinedata {
info: Info
}
type Info {
ourid: String!
title: String!
code: String!
source: String!
}
`
这是我的问题
{
getCountryData{
countrytimelinedata{
info{
code
}
}
}
};
我不确定我是否构造了错误的东西。我尝试了另一个模式,其中它的值是下面的,不管怎样,它仍然是空的
extend type Query {
countrytimelinedata: [countrytimelinedata]
timelineitems: [TimelineItem]
}
感谢您的帮助,如果这是显而易见的,对graphQL来说还是非常新的,那么很抱歉,看起来我犯了经典的承诺处理错误。我需要显式返回res.data对象
Query: {
getCountryData: (parent, args) => {
return axios
.get(`https://thevirustracker.com/free-api?countryTimeline=US`)
.then((res) => {
console.log(res.data);
return res.data; <<<< add return here
});
},
},
};