I am trying to add the totalcount of records to be used for pagination. Right now i can see the connection i am having trouble modifying it to get my totalCount to be apart of it.
Books: {
type: BooksConnection.connectionType,
args: { ...connectionArgs, isbn: { type: GraphQLString }, publisher: {type: GraphQLString}},
resolve: ( obj, { ...args }, context, { rootValue: objectManager } ) =>
{
let user = obj;
let FormatedArgs = MasterFields.FormatPredicate(args);
return objectManager.getListBy( 'Book', user, FormatedArgs.queryArgs, objectManager.getViewerUserId( ) ).then( ( arr ) =>
{
let result = {};
result.Books = arr;
result.totalCount = arr.length;
;
//Originally i would just pass arr instead of result.
return connectionFromArray( result, FormatedArgs.connArgs);
} )
}
},
When i get the connection object in the BookConnection in this case. I want to be able to assign that value to a field.
export default connectionDefinitions( {
name: 'Books',
nodeType: BookType,
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
resolve: (connection) => { console.log(connection); return connection.totalCount; },
description: `A count of the total number of objects in this connection, ignoring pagination.
This allows a client to fetch the first five objects by passing "5" as the
argument to "first", then fetch the total count so it could display "5 of 83",
for example.`
}
})
});
How can I make totalCount
a property of the connection
variable?
I found part of the answer here: How to pass total count to the client in pageInfo