我正在尝试添加要用于分页的记录总数。现在我可以看到我无法修改它以使我的 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
我在这里找到了部分答案:How to pass total count to the client in pageInfo