Я пытаюсь добавить общее количество записей, которые будут использоваться для разбивки на страницы. Прямо сейчас я вижу соединение, у меня проблемы с его изменением, чтобы мой totalCount был отдельным от него.
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);
} )
}
},
Когда я получаю объект подключения в BookConnection в этом случае. Я хочу иметь возможность присвоить это значение полю.
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.`
}
})
});
Как сделать totalCount
свойством переменной connection
?
Я нашел здесь часть ответа: Как передать общую посчитать клиенту в pageInfo