@entria/graphql-mongoose-loader
Version:
GraphQL Mongoose Loader helpers
32 lines (31 loc) • 1.1 kB
TypeScript
import { ConnectionArguments } from 'graphql-relay';
import mongoose, { Aggregate } from 'mongoose';
declare type ObjectId = mongoose.Schema.Types.ObjectId;
export declare type ConnectionOptionsAggregate<LoaderResult, Ctx> = {
aggregate: Aggregate<any>;
context: Ctx;
args: ConnectionArguments;
loader: (ctx: Ctx, id: string | ObjectId | Object) => LoaderResult;
raw?: boolean;
allowDiskUse?: boolean;
};
/**
* Your aggregate must return documents with _id fields
* those _id's are the ones going to be passed to the loader function
*/
declare function connectionFromMongoAggregate<LoaderResult, Ctx>({ aggregate, context, args, loader, raw, allowDiskUse, }: ConnectionOptionsAggregate<LoaderResult, Ctx>): Promise<{
edges: {
cursor: string;
node: LoaderResult;
}[];
count: number;
endCursorOffset: number;
startCursorOffset: number;
pageInfo: {
startCursor: string | null;
endCursor: string | null;
hasPreviousPage: boolean;
hasNextPage: boolean;
};
}>;
export default connectionFromMongoAggregate;