Interface: RelayPaginateQueryHelper
Example
// 1. Create an interface representing a document in MongoDB.
interface User {
_id: mongoose.Types.ObjectId;
myId: number;
name: string;
email: string;
avatar?: string;
}
// 2. Setup various types.
type UserModel = Model<User, RelayPaginateQueryHelper> & RelayPaginateStatics;
// 3. Create a Schema corresponding to the document interface.
const schema = new Schema<User, UserModel>({
myId: Number,
name: { type: String, required: true },
email: { type: String, required: true },
avatar: String,
});
// 4. Create your Model.
const UserModel = model<User, UserModel>("User", schema);
@public
Methods
relayPaginate
▸ relayPaginate<Q
>(this
, paginateInfo?
): Query
<RelayResult
<IfAny
<QueryResult
<Q
>, any
, QueryDocType
<Q
> extends Record
<string
, never
> ? Document
<unknown
, QueryHelpers
<Q
>, QueryResult
<Q
>> & Require_id
<QueryResult
<Q
>> : IfAny
<QueryDocType
<Q
>, Document
<unknown
, QueryHelpers
<Q
>, QueryResult
<Q
>> & Require_id
<QueryResult
<Q
>>, Document
<unknown
, QueryHelpers
<Q
>, QueryResult
<Q
>> & Omit
<Require_id
<QueryResult
<Q
>>, keyof QueryDocType
<Q
>> & QueryDocType
<Q
>>>[]>, QueryDocType
<Q
>, QueryHelpers
<Q
>, QueryRawDocType
<Q
>, "find"
> & QueryHelpers
<Q
>
This is an implementation of the relay pagination algorithm for mongoose. This algorithm and pagination format allows one to use cursor based pagination.
For more on cursors see PagingCursor
For more info on using cursor based pagination algorithms like relay see:
the documentation for relay's connection spec (look at this one for docs in more laymans terms),
the actual relay spec (look at this one for very exact and concise, but possibly confusing language),
Type parameters
Name | Type |
---|---|
Q | extends Query <unknown [], unknown , unknown , unknown , "find" , Q > |
Parameters
Name | Type | Description |
---|---|---|
this | Q | the query to add pagination to |
paginateInfo? | Partial <MongooseRelayPaginateInfo <Q >> | - |
Returns
Query
<RelayResult
<IfAny
<QueryResult
<Q
>, any
, QueryDocType
<Q
> extends Record
<string
, never
> ? Document
<unknown
, QueryHelpers
<Q
>, QueryResult
<Q
>> & Require_id
<QueryResult
<Q
>> : IfAny
<QueryDocType
<Q
>, Document
<unknown
, QueryHelpers
<Q
>, QueryResult
<Q
>> & Require_id
<QueryResult
<Q
>>, Document
<unknown
, QueryHelpers
<Q
>, QueryResult
<Q
>> & Omit
<Require_id
<QueryResult
<Q
>>, keyof QueryDocType
<Q
>> & QueryDocType
<Q
>>>[]>, QueryDocType
<Q
>, QueryHelpers
<Q
>, QueryRawDocType
<Q
>, "find"
> & QueryHelpers
<Q
>