如何解决从外部解析器调用 dataSource api 进行调试
我想调用我的 RESTDatasource
API,而不必在解析器中调用它。
class MyAPI extends RESTDatasource {
constructor(){
super();
this.baseURL = "https://myendpoint.com/data"
}
async getData(endpoint){
this.get(`{endopoint}.json`)
}
}
const resolvers = {
Query: {
endpoint: (_,__,{ dataSources }) => {
datasources.myAPI.getData(); //I can only call my api here
}
}
}
现在,每次我想检查我的 API 是如何工作的,以及在我使用 grapqhiql
执行解析器之后,我都会修改我的端点解析器,以便我可以查看 api.getData()
的返回
如何在测试中调用我的 api 以便在我开发时与该 API 交互?
//test.ts
import MyAPI from "./myAPI"
it("Calls myAPI",() => {
const api = new MyAPI();
api.getData(); //I want to access this context so I can play around with getData returns
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。