Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
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)
}
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,
})
})
},
}
resolve: (root, options, request, { rootValue: { accessToken } }) => {
if (!accessToken) return null
const { limit: size, offset } = getPagingParameters(options)
const gravityArgs = {
size,
offset,
total_count: true,
}
return gravity.with(accessToken, { headers: true })("me/follow/artists", gravityArgs).then(({ body, headers }) => {
return connectionFromArraySlice(body, options, {
arrayLength: headers["x-total-count"],
sliceStart: offset,
})
})
},
}
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,
})
})
},
}
resolve: (
{ recently_viewed_artwork_ids: ids },
options,
{ artworksLoader }
) => {
if (ids.length === 0) {
return connectionFromArray(ids, options)
}
const { offset } = getPagingParameters(options)
return artworksLoader({ ids }).then(body => {
return connectionFromArraySlice(body, options, {
arrayLength: body.length,
sliceStart: offset,
})
})
},
}
resolve: (
sale,
options,
request,
{ rootValue: { saleArtworksLoader } },
) => {
const { limit: size, offset } = getPagingParameters(options)
return saleArtworksLoader(sale.id, { size, offset }).then(({ body }) =>
connectionFromArraySlice(body, options, {
arrayLength: sale.eligible_sale_artworks_count,
sliceStart: offset,
}))
},
},
resolve: (gene, { excludeGeneIDs }, { similarGenesLoader }) => {
const options: any = {
exclude_gene_ids: excludeGeneIDs,
}
const { limit: size, offset } = getPagingParameters(options)
const gravityArgs = {
size,
offset,
exclude_gene_ids: options.exclude_gene_ids,
total_count: true,
}
return similarGenesLoader(gene.id, gravityArgs).then(
({ body, headers }) => {
const genes = body
const totalCount = parseInt(headers["x-total-count"] || "0", 10)
return connectionFromArraySlice(genes, options, {
arrayLength: totalCount,
sliceStart: offset,
})