Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console.log resolver data in graphql

Tags:

graphql

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?

like image 605
Roger Dodger Avatar asked Oct 23 '18 18:10

Roger Dodger


People also ask

How does GraphQL work in Apollo server?

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.

What is resolver in GraphQL-compose?

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)

How many arguments does every resolver function in a GraphQL schema accept?

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 !!!"

What is a resolver in SQL Server?

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.


1 Answers

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.

like image 99
Marco Daniel Avatar answered Sep 28 '22 14:09

Marco Daniel