Issue Hey everyone,
I'm having trouble with implementing a search resolver. The resolver search
is supposed to take a query as a parameter and then use the useSearch
function to retrieve data. However, I keep getting an error, which is displayed at the bottom of this message.
If anyone can offer assistance in resolving this issue, I would greatly appreciate it.
Custom Hooks
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;
};
Resolvers
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;
}
}
Error
(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.