Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (direction !== 'ASC' && direction !== 'DESC') {
throw new Error (direction + ' is not a valid sorting direction')
}
orderColumns[column] = direction
}
} else if (typeof node.orderBy === 'string') {
orderColumns[node.orderBy] = 'ASC'
} else {
throw new Error('"orderBy" is required for pagination')
}
let limit = 'ALL', offset = 0
if (node.args && node.args.first) {
// we'll get one extra item (hence the +1). this is to determine if there is a next page or not
limit = parseInt(node.args.first) + 1
if (node.args.after) {
offset = cursorToOffset(node.args.after) + 1
}
}
return { limit, offset, orderColumns }
}
resolve: ({}, args) => {
logger.info('Resolving queryProductList with params:', { args });
const start = args.after ? cursorToOffset(args.after) + 1 : 0;
const size = (args.first || 8) + 1;
const result = productService.findAll({ start, size });
// support pagination
const array = args.after ? new Array(start).concat(result.items) : result.items;
return connectionFromArray(
array,
args,
);
},
},
const cursor = {}
const key = sortKey.key
for (let column of wrap(key)) {
cursor[column] = obj[column]
}
return { cursor: objToCursor(cursor), node: obj }
})
if (data.length) {
pageInfo.startCursor = edges[0].cursor
pageInfo.endCursor = last(edges).cursor
}
return { edges, pageInfo, _paginated: true }
} else if (sqlAST.orderBy || (sqlAST.junction && sqlAST.junction.orderBy)) {
let offset = 0
if (idx(sqlAST, _ => _.args.after)) {
offset = cursorToOffset(sqlAST.args.after) + 1
}
// $total was a special column for determining the total number of items
const arrayLength = data[0] && parseInt(data[0].$total, 10)
const connection = connectionFromArraySlice(data, sqlAST.args || {}, { sliceStart: offset, arrayLength })
connection.total = arrayLength || 0
connection._paginated = true
return connection
}
}
return data
}
export function getPagingParameters(args: ConnectionArgs) {
const meta = getMeta(args);
switch (meta.pagingType) {
case 'forward': {
return {
limit: meta.first,
offset: meta.after ? Relay.cursorToOffset(meta.after) + 1 : 0,
};
}
case 'backward': {
const { last, before } = meta;
let limit = last;
let offset = Relay.cursorToOffset(before!) - last;
// Check to see if our before-page is underflowing past the 0th item
if (offset < 0) {
// Adjust the limit with the underflow value
limit = Math.max(last + offset, 0);
offset = 0;
}
return { offset, limit };
}
default:
return {};
}
}
export function getPagingParameters(args: ConnectionArgs) {
const meta = getMeta(args);
switch (meta.pagingType) {
case 'forward': {
return {
limit: meta.first,
offset: meta.after ? Relay.cursorToOffset(meta.after) + 1 : 0,
};
}
case 'backward': {
const { last, before } = meta;
let limit = last;
let offset = Relay.cursorToOffset(before!) - last;
// Check to see if our before-page is underflowing past the 0th item
if (offset < 0) {
// Adjust the limit with the underflow value
limit = Math.max(last + offset, 0);
offset = 0;
}
return { offset, limit };
}
if (direction !== 'ASC' && direction !== 'DESC') {
throw new Error (direction + ' is not a valid sorting direction')
}
orderColumns[column] = direction
}
} else if (typeof node.orderBy === 'string') {
orderColumns[node.orderBy] = 'ASC'
} else {
throw new Error('"orderBy" is required for pagination')
}
let limit = '18446744073709551615', offset = 0
if (node.args && node.args.first) {
// we'll get one extra item (hence the +1). this is to determine if there is a next page or not
limit = parseInt(node.args.first) + 1
if (node.args.after) {
offset = cursorToOffset(node.args.after) + 1
}
}
return { limit, offset, orderColumns }
}
function orderColumnsToString(orderColumns) {
let needToPreCount = false;
// Validates the skip input
if (skipInput || skipInput === 0) {
if (skipInput < 0) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
'Skip should be a positive number'
);
}
skip = skipInput;
}
// Validates the after param
if (after) {
after = cursorToOffset(after);
if ((!after && after !== 0) || after < 0) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,
'After is not a valid cursor'
);
}
// If skip and after are passed, a new skip is calculated by adding them
skip = (skip || 0) + (after + 1);
}
// Validates the first param
if (first || first === 0) {
if (first < 0) {
throw new Parse.Error(
Parse.Error.INVALID_QUERY,