How to use the graphql-relay.connectionFromArraySlice function in graphql-relay

To help you get started, we’ve selected a few graphql-relay 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 / schema / gene.js View on Github external
.then(({ aggregations, hits }) => {
              return Object.assign(
                { aggregations }, // Add data to connection so the `aggregations` connection field can resolve it
                connectionFromArraySlice(hits, options, {
                  arrayLength: aggregations.total.value,
                  sliceStart: gravityOptions.offset,
                })
              )
            })
        },
github kriasoft / nodejs-api-starter / src / schema.js View on Github external
async resolve(root, args) {
          const limit = typeof args.first === 'undefined' ? '10' : args.first;
          const offset = args.after ? cursorToOffset(args.after) + 1 : 0;

          const [data, totalCount] = await Promise.all([
            db.table('stories')
              .orderBy('created_at', 'desc')
              .limit(limit).offset(offset)
              .then(rows => rows.map(x => Object.assign(x, { __type: 'Story' }))),
            db.table('stories')
              .count().then(x => x[0].count),
          ]);

          return {
            ...connectionFromArraySlice(data, args, {
              sliceStart: offset,
              arrayLength: totalCount,
            }),
            totalCount,
          };
        },
      },
github artsy / metaphysics / src / schema / v2 / me / followed_fairs.ts View on Github external
return followedFairsLoader(gravityArgs).then(({ body, headers }) => {
      return connectionFromArraySlice(body, options, {
        arrayLength: parseInt(headers["x-total-count"] || "0", 10),
        sliceStart: offset,
        resolveNode: follow_profile => follow_profile.profile.owner,
      })
    })
  },
github artsy / metaphysics / src / schema / filter_artworks.ts View on Github external
({ aggregations, hits }) => {
            if (!aggregations || !aggregations.total) {
              throw new Error("This query must contain the total aggregation")
            }

            const totalPages = computeTotalPages(
              aggregations.total.value,
              relayOptions.size
            )

            const connection = connectionFromArraySlice(hits, args, {
              arrayLength: Math.min(
                aggregations.total.value,
                totalPages * relayOptions.size
              ),
              sliceStart: relayOptions.offset,
            })

            connection.pageInfo.endCursor = pageToCursor(page + 1, size)

            return Object.assign(
              {
                pageCursors: createPageCursors(
                  relayOptions,
                  aggregations.total.value
                ),
              },
github artsy / metaphysics / src / schema / me / followed_artists_artworks_group.ts View on Github external
resolve: ({ artworks }, args) => {
        return connectionFromArraySlice(artworks, args, {
          arrayLength: artworks.length,
          sliceStart: 0,
        })
      },
    },
github artsy / metaphysics / src / schema / fair.ts View on Github external
artists => {
                return connectionFromArraySlice(artists, options, {
                  arrayLength: parseInt(headers["x-total-count"] || "0", 10),
                  sliceStart: gravityOptions.offset,
                })
              }
            )
github artsy / metaphysics / src / schema / v1 / artist / index.ts View on Github external
).then(({ results, count }) => {
            const totalPages = Math.ceil(count / size)
            return merge(
              { pageCursors: createPageCursors(pageOptions, count) },
              connectionFromArraySlice(results, args, {
                arrayLength: count,
                sliceStart: offset,
              }),
              {
                pageInfo: {
                  hasPreviousPage: page > 1,
                  hasNextPage: page < totalPages,
                },
              }
            )
          })
        },
github artsy / metaphysics / src / schema / v2 / me / credit_cards.ts View on Github external
return meCreditCardsLoader(gravityArgs).then(({ body, headers }) => {
      return connectionFromArraySlice(body, options, {
        arrayLength: parseInt(headers["x-total-count"] || "0", 10),
        sliceStart: offset,
      })
    })
  },
github artsy / metaphysics / src / schema / me / recently_viewed_artworks.ts View on Github external
return artworksLoader({ ids }).then(body => {
      return connectionFromArraySlice(body, options, {
        arrayLength: body.length,
        sliceStart: offset,
      })
    })
  },
github artsy / metaphysics / src / schema / v2 / filterArtworksConnection.ts View on Github external
resolve: (
        { options: gravityOptions, aggregations, hits },
        args,
        _context
      ) => {
        if (!aggregations || !aggregations.total) {
          throw new Error("This query must contain the total aggregation")
        }

        const totalPages = computeTotalPages(
          aggregations.total.value,
          gravityOptions.size
        )

        const connection = connectionFromArraySlice(hits, args, {
          arrayLength: Math.min(
            aggregations.total.value,
            totalPages * gravityOptions.size
          ),
          sliceStart: gravityOptions.offset,
        })

        connection.pageInfo.endCursor = pageToCursor(
          gravityOptions.page + 1,
          gravityOptions.size
        )

        return Object.assign(
          {
            pageCursors: createPageCursors(
              gravityOptions,