valu-digital / wp-graphql-offset-pagination

Adds traditional offset pagination support to WPGraphQL
73 stars 17 forks source link

How do I make my custom connector compatible? #6

Open bruno-barros opened 4 years ago

bruno-barros commented 4 years ago

I'm implementing a custom connector to read data from tables that are not from default WP tables. I'm getting the data, but I have no clue on how to pass propper data to do offset pagination. Can you give me a tip? Thanks

bruno-barros commented 4 years ago

hummm seems to be impossible. I have may own class to query results. If you allow any class with a XYZ method to retrieve the total would be awesome.

        $total = null;

        if ($query instanceof \WP_Query) {
            $total = $query->found_posts;
        } elseif ($query instanceof \WP_User_Query) {
            $total = $query->total_users;
        }
bruno-barros commented 4 years ago

This way it works.

        if ($query instanceof \WP_Query) {
            $total = $query->found_posts;
        } elseif ($query instanceof \WP_User_Query) {
            $total = $query->total_users;
        } else if(method_exists($resolver, 'get_total_records')){
            $total = $resolver->get_total_records();
        }