How to use relay-cursor-paging - 10 common examples

To help you get started, we’ve selected a few relay-cursor-paging examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github artsy / metaphysics / src / lib / helpers.ts View on Github external
export const convertConnectionArgsToGravityArgs = (
  options: T
) => {
  const { limit: size, offset } = getPagingParameters(options)
  // If a size of 0 explicitly requested, it doesn't really matter what
  // the page is.
  const page = size ? Math.round((size + offset) / size) : 1
  const gravityArgs = omit(options, ["first", "after", "last", "before"])
  return Object.assign({}, { page, size, offset }, gravityArgs)
}
github artsy / metaphysics / src / schema / v1 / gene_families.ts View on Github external
import {
  connectionDefinitions,
  connectionFromPromisedArray,
} from "graphql-relay"
import { convertConnectionArgsToGravityArgs } from "lib/helpers"
import { GraphQLFieldConfig } from "graphql"
import { ResolverContext } from "types/graphql"

const { connectionType: GeneFamilyConnection } = connectionDefinitions({
  nodeType: GeneFamilyType,
})

const GeneFamilies: GraphQLFieldConfig = {
  type: GeneFamilyConnection,
  description: "A list of Gene Families",
  args: pageable(),
  resolve: (_root, options, { geneFamiliesLoader }) => {
    const gravityOptions = Object.assign(
      {},
      convertConnectionArgsToGravityArgs(options),
      {
        sort: "position",
      }
    )
    return connectionFromPromisedArray(
      geneFamiliesLoader(gravityOptions),
      // FIXME: Need to type properly
      // @ts-ignore
      gravityOptions
    )
  },
}
github artsy / metaphysics / src / schema / partner_show.ts View on Github external
} else {
              fetch = partnerShowArtworksLoader(
                { partner_id: show.partner.id, show_id: show.id },
                options
              ).then(({ body }) => body)
            }

            // @ts-ignore
            // FIXME: Update with Gravity param when ready
            return fetch.then(exclude(options.exclude, "id"))
          },
        },
        artworksConnection: {
          description: "A connection of artworks featured in the show",
          type: artworkConnection,
          args: pageable(artworksArgs),
          resolve: (show, options, { partnerShowArtworksLoader }) => {
            const loaderOptions = {
              partner_id: show.partner.id,
              show_id: show.id,
            }
            const { page, size, offset } = convertConnectionArgsToGravityArgs(
              options
            )

            interface GravityArgs {
              exclude_ids?: string[]
              page: number
              size: number
              total_count: boolean
            }
github artsy / metaphysics / src / schema / v2 / artist / shows.ts View on Github external
resolve: ({ id }, options, { relatedShowsLoader }) => {
    return relatedShowsLoader(
      defaults(options, {
        artist_id: id,
        sort: "-end_at",
      })
    ).then(({ body: shows }) => showsWithBLacklistedPartnersRemoved(shows))
  },
}

export const ShowsConnectionField: GraphQLFieldConfig<
  { id: string },
  ResolverContext
> = {
  type: ShowsConnection,
  args: pageable(ShowArgs),
  resolve: ({ id }, args, { relatedShowsLoader }) => {
    const pageOptions = convertConnectionArgsToGravityArgs(args)
    const { page, size, offset } = pageOptions
    const gravityArgs = omit(args, ["first", "after", "last", "before"])
    return relatedShowsLoader(
      defaults(gravityArgs, pageOptions, {
        artist_id: id,
        sort: "-end_at",
        total_count: true,
      })
    )
      .then(({ body, headers }) => {
        const whitelistedShows = showsWithBLacklistedPartnersRemoved(body)
        return { body: whitelistedShows, headers }
      })
      .then(({ body, headers }) => {
github artsy / metaphysics / src / lib / helpers.ts View on Github external
export const convertConnectionArgsToGravityArgs = (
  options: T
) => {
  const { limit: size, offset } = getPagingParameters(
    options
  ) as PagingParameters
  const page = Math.round((size + offset) / size)
  const gravityArgs = omit(options, ["first", "after", "last", "before"])
  return Object.assign({}, { page, size, offset }, gravityArgs)
}
github artsy / metaphysics / src / schema / v2 / artwork / artworkContextGrids / index.ts View on Github external
fields: () => ({
    title: {
      type: GraphQLString,
    },
    ctaTitle: {
      type: GraphQLString,
    },
    ctaHref: {
      type: GraphQLString,
    },
    artworks: {
      type: artworkConnection,
      args: pageable(),
    },
  }),
  resolveType,
github artsy / metaphysics / src / schema / v1 / artwork / artworkContextGrids / index.ts View on Github external
fields: () => ({
    title: {
      type: GraphQLString,
    },
    ctaTitle: {
      type: GraphQLString,
    },
    ctaHref: {
      type: GraphQLString,
    },
    artworks: {
      type: artworkConnection,
      args: pageable(),
    },
  }),
  resolveType,
github artsy / metaphysics / schema / me / artwork_inquiries.js View on Github external
artwork: {
      type: new GraphQLNonNull(Artwork.type),
      resolve: ({ inquireable }) => inquireable,
    },
    id: {
      type: GraphQLID,
    },
    impulse_conversation_id: {
      type: GraphQLString,
    },
  }),
})

export default {
  type: connectionDefinitions({ nodeType: ArtworkInquiryType }).connectionType,
  args: pageable({}),
  description: "A list of the current user’s inquiry requests",
  resolve: (root, options, request, { rootValue: { accessToken } }) => {
    if (!accessToken) return null
    const { limit: size, offset } = getPagingParameters(options)
    const gravityArgs = {
      size,
      offset,
      inquireable_type: "artwork",
      total_count: true,
    }
    return gravity.with(accessToken, { headers: true })(
      "me/inquiry_requests",
      gravityArgs
    ).then(({ body, headers }) => {
      return connectionFromArraySlice(body, options, {
        arrayLength: headers["x-total-count"],
github artsy / metaphysics / src / schema / v2 / me / artwork_inquiries.ts View on Github external
fields: () => ({
    ...InternalIDFields,
    artwork: {
      type: new GraphQLNonNull(Artwork.type),
      resolve: ({ inquireable }) => inquireable,
    },
    impulseConversationID: {
      type: GraphQLString,
      resolve: ({ impulse_conversation_id }) => impulse_conversation_id,
    },
  }),
})

const ArtworkInquiries: GraphQLFieldConfig = {
  type: connectionDefinitions({ nodeType: ArtworkInquiryType }).connectionType,
  args: pageable({}),
  description: "A list of the current user’s inquiry requests",
  resolve: (_root, options, { inquiryRequestsLoader }) => {
    if (!inquiryRequestsLoader) return null
    const { limit: size, offset } = getPagingParameters(options)
    const gravityArgs = {
      size,
      offset,
      inquireable_type: "artwork",
      total_count: true,
    }
    return inquiryRequestsLoader(gravityArgs).then(({ body, headers }) => {
      return connectionFromArraySlice(body, options, {
        arrayLength: parseInt(headers["x-total-count"] || "0", 10),
        sliceStart: offset,
      })
    })
github artsy / metaphysics / src / schema / v2 / me / artwork_inquiries.ts View on Github external
resolve: (_root, options, { inquiryRequestsLoader }) => {
    if (!inquiryRequestsLoader) return null
    const { limit: size, offset } = getPagingParameters(options)
    const gravityArgs = {
      size,
      offset,
      inquireable_type: "artwork",
      total_count: true,
    }
    return inquiryRequestsLoader(gravityArgs).then(({ body, headers }) => {
      return connectionFromArraySlice(body, options, {
        arrayLength: parseInt(headers["x-total-count"] || "0", 10),
        sliceStart: offset,
      })
    })
  },
}

relay-cursor-paging

Relay Cursor-Based Pagination Support for Sequelize

MIT
Latest version published 7 years ago

Package Health Score

42 / 100
Full package analysis