如何解决类型定义查询返回 null
制作第三方api,这是有效的。当我尝试从调用中返回数据时,我的 Query 只在操场上显示 null。任何帮助,将不胜感激。我的控制台登录 RESDataSource 正是我需要的对象信息。
**type-def**
export const typeDefs = gql`
type Query {
testApi: Soccer
}
type Soccer {
leagueName: String
leagueId: String
}
`;
解析器
export const resolvers = {
Query: {
// testMessage: () => 'Ayyyy We Live!',testApi: (_,args,{ dataSources }) => {
dataSources.soccerApi.getLeagues();
},},};
数据源
class SoccerAPI extends RESTDataSource {
constructor() {
super()
this.baseURL = 'https://api.soccersapi.com/v2.2/leagues/'
}
async getLeagues() {
const response = await this.get('******Sensitive Info Was Here********')
let foo = this.leagueReducer(response);
console.log("Foo",foo)
return foo;
}
leagueReducer(res) {
let soccer = {
leagueName: res.data[0].name,leagueId : res.data[0].id
}
// console.log(soccer)
return soccer;
}
}
服务器
const apolloServer = new ApolloServer({ 解析器, 类型定义, 数据源:() => ({ FootballApi: 新的 SoccerApi() }) });
export const graphqlHandler = apolloServer.createHandler();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。