Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function resolveBrowse(
root,
{ first, after, type = [], status = [], discID, isrc, iswc, ...args },
{ loaders },
info
) {
const pluralName = toDashed(info.fieldName)
const singularName = toSingular(pluralName)
let params = {
...args,
type,
status,
limit: first,
offset: getOffsetWithDefault(after, -1) + 1 || undefined
}
params = includeSubqueries(params, info)
params = includeRelationships(params, info, info.fragments)
const formatParam = value => value.toLowerCase().replace(/ /g, '')
params.type = params.type.map(formatParam)
params.status = params.status.map(formatParam)
let request
if (discID) {
request = loaders.lookup.load(['discid', discID, params])
// If fetching releases by disc ID, they will already include the `media`
// and `discids` subqueries, and it is invalid to specify them.
if (params.inc) {
params.inc = params.inc.filter(value => {
return value !== 'media' && value !== 'discids'
})
}
export function resolveSearch(
root,
{ after, first, query, ...args },
{ loaders },
info
) {
const pluralName = toDashed(info.fieldName)
const singularName = toSingular(pluralName)
let params = {
...args,
limit: first,
offset: getOffsetWithDefault(after, -1) + 1 || undefined
}
params = includeSubqueries(params, info)
return loaders.search.load([singularName, query, params]).then(list => {
const {
[pluralName]: arraySlice,
offset: sliceStart,
count: arrayLength
} = list
const meta = { sliceStart, arrayLength }
const connection = connectionFromArraySlice(
arraySlice,
{ first, after },
meta
)
// Move the `score` field up to the edge object and make sure it's a
// number (MusicBrainz returns a string).
constructor(protected array: TEdgeSource[], args: ConnectionArguments) {
super(args);
const { after, before, first, last } = args;
const arrayLength = array.length;
const beforeOffset = getOffsetWithDefault(before, arrayLength);
const afterOffset = getOffsetWithDefault(after, -1);
let startOffset = Math.max(afterOffset + 1, 0);
let endOffset = Math.min(beforeOffset, arrayLength);
if (typeof first === 'number') {
endOffset = Math.min(endOffset, startOffset + first);
}
if (typeof last === 'number') {
startOffset = Math.max(startOffset, endOffset - last);
}
this.startOffset = startOffset;
this.endOffset = endOffset;
this.afterOffset = afterOffset;
this.beforeOffset = beforeOffset;
}
constructor(protected array: TEdgeSource[], args: ConnectionArguments) {
super(args);
const { after, before, first, last } = args;
const arrayLength = array.length;
const beforeOffset = getOffsetWithDefault(before, arrayLength);
const afterOffset = getOffsetWithDefault(after, -1);
let startOffset = Math.max(afterOffset + 1, 0);
let endOffset = Math.min(beforeOffset, arrayLength);
if (typeof first === 'number') {
endOffset = Math.min(endOffset, startOffset + first);
}
if (typeof last === 'number') {
startOffset = Math.max(startOffset, endOffset - last);
}
this.startOffset = startOffset;
this.endOffset = endOffset;
this.afterOffset = afterOffset;
this.beforeOffset = beforeOffset;
}