Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.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,
})
)
})
},
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,
};
},
},
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,
})
})
},
({ 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
),
},
resolve: ({ artworks }, args) => {
return connectionFromArraySlice(artworks, args, {
arrayLength: artworks.length,
sliceStart: 0,
})
},
},
artists => {
return connectionFromArraySlice(artists, options, {
arrayLength: parseInt(headers["x-total-count"] || "0", 10),
sliceStart: gravityOptions.offset,
})
}
)
).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,
},
}
)
})
},
return meCreditCardsLoader(gravityArgs).then(({ body, headers }) => {
return connectionFromArraySlice(body, options, {
arrayLength: parseInt(headers["x-total-count"] || "0", 10),
sliceStart: offset,
})
})
},
return artworksLoader({ ids }).then(body => {
return connectionFromArraySlice(body, options, {
arrayLength: body.length,
sliceStart: offset,
})
})
},
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,