I'm trying to console.log the resolver in a graphql app. The graphiql part works (I can start the server and see the graphql dashboard and then use the root query to retrieve the results in the browser pane), but I'm unable to console.log the same results in my browser console. Following is my code:
const GetBooks = {
type: new GraphQLList(BookTypes),
args: {},
resolve() {
return new Promise((resolve, reject) => {
let sql = singleLineString`
select * from books
`;
sql = mysql.format(sql);
pool.query(sql, (err, results) => {
if (err) {
reject(err);
}
resolve(results);
console.log(resolve(results));
});
});
}
};
The part that is 'not working' is the console.log(resolve(results)) part of the code. Can someone point out why this isn't working?
How Apollo Server processes GraphQL operations Apollo Server needs to know how to populate data for every field in your schema so that it can respond to requests for that data. To accomplish this, it uses resolvers. A resolver is a function that's responsible for populating the data for a single field in your schema.
In terms of graphql-compose this field config is called as Resolver. The main aim of Resolver is to keep available resolve methods for Type and use them for building relation with other types. Resolver provide following abilities: wrap args, type, resolve (get resolver and create new one with extended/modified functionality)
Every resolver function in a GraphQL schema accepts four positional arguments as given below − //resolver function with no parameters and returning string greeting: () => { return "hello from TutorialsPoint !!!"
A resolver is a function that's responsible for populating the data for a single field in your schema. It can populate that data in any way you define, such as by fetching data from a back-end database or a third-party API.
The console.log
you are using is not on the client side.
It logs the result on the server side, not on the browser. Check your command line that started the GraphQL server, the logs should be there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With