Noah's Pairwise Manifest

    relay-cursor-paging
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.0 • Public • Published

    Build Status

    relay-cursor-paging

    Relay Cursor-Based Pagination Support for Databases

    API:

    getPagingParameters(args): Emits an object with limit and criteria fields based on Relay's pagination fields (e.g. first, after, last, and before).

    pageable(argSpec): Emits an augmented Argument Specification with first, after, before, and last arguments.

    import { pageable, getPagingParameters } from "relay-cursor-paging";
    const { connectionFromPromisedArraySlice } = require("graphql-relay");
     
    const myType = new GraphQLObjectType({
        fields: () => {  
            relatedThings: {      
                type: thingConnection,
                args: pageable({}), // Adds first, after, last, and before arguments
                resolve: (root, args) => {
                    const { limit, offset } = getPagingParameters(args);                
                    const criteria = makeCriteria(args, limit, offset);
                                                                
                    return connectionFromPromisedArraySlice(
                        thingRepository.findAll(criteria),
                        args, 
                        {
                            sliceStart: 0,
                            arrayLength: // count query result
                        }
                    );
                }
            }
        }
    });

    Install

    npm i relay-cursor-paging

    DownloadsWeekly Downloads

    2,255

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • darthtrevino