【发布时间】:2020-05-22 23:32:30
【问题描述】:
问题 朋友们好,
我正在尝试执行搜索,但显然执行不正确。 resolver search 应该接收一个查询作为参数,然后使用useSearch 函数将返回数据。但它向我显示了一个错误,您可以在底部看到它。
如果有人可以帮助我解决问题,我将不胜感激。
挂钩
export async function useSearch(query: String){
const data = await axios.get(`${BASE_URL}/Search/${query}`)
.then(res =>{
return res.data.search;
}).catch(err =>{
console.log(err)
});
return data;
};
解析器
import { Query , Resolver, Args} from '@nestjs/graphql';
import {
useLatestAnime,
useSearch
} from './hooks/index';
@Resolver()
export class AnimesResolver{
latestAnime = useLatestAnime()
.then(res =>{
return res;
});
search = (query: String) =>{
const data = useSearch(query)
.then(res =>{
return res;
});
return data;
}
@Query('latestAnime')
getLatestAnime(){
const data = this.latestAnime.then(res =>{
return res;
})
return data;
}
@Query('search')
getSearch(@Args('query') query: String){
const res = this.search(query)
.then(res =>{
return res;
})
return res;
}
}
错误
(node:11940) UnhandledPromiseRejectionWarning: Error: Query.search defined in resolvers, but not in schema
(node:11940) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 2)
(node:11940) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
标签: typescript graphql nestjs