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)
}
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
)
},
}
} 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
}
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 }) => {
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)
}
fields: () => ({
title: {
type: GraphQLString,
},
ctaTitle: {
type: GraphQLString,
},
ctaHref: {
type: GraphQLString,
},
artworks: {
type: artworkConnection,
args: pageable(),
},
}),
resolveType,
fields: () => ({
title: {
type: GraphQLString,
},
ctaTitle: {
type: GraphQLString,
},
ctaHref: {
type: GraphQLString,
},
artworks: {
type: artworkConnection,
args: pageable(),
},
}),
resolveType,
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"],
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,
})
})
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,
})
})
},
}