Prettier some files + opti object relation (#7044)
This commit is contained in:
@@ -10,10 +10,10 @@ const needToGetAllKeys = (fields, keys, parseClasses) =>
|
||||
? keys.split(',').some(keyName => {
|
||||
const key = keyName.split('.');
|
||||
if (fields[key[0]]) {
|
||||
if (fields[key[0]].type === 'Relation') return false;
|
||||
if (fields[key[0]].type === 'Pointer') {
|
||||
const subClass = parseClasses.find(
|
||||
({ className: parseClassName }) =>
|
||||
fields[key[0]].targetClass === parseClassName
|
||||
({ className: parseClassName }) => fields[key[0]].targetClass === parseClassName
|
||||
);
|
||||
if (subClass && subClass.fields[key[1]]) {
|
||||
// Current sub key is not custom
|
||||
@@ -50,9 +50,7 @@ const getObject = async (
|
||||
try {
|
||||
if (
|
||||
!needToGetAllKeys(
|
||||
parseClasses.find(
|
||||
({ className: parseClassName }) => className === parseClassName
|
||||
).fields,
|
||||
parseClasses.find(({ className: parseClassName }) => className === parseClassName).fields,
|
||||
keys,
|
||||
parseClasses
|
||||
)
|
||||
@@ -141,15 +139,7 @@ const findObjects = async (
|
||||
preCountOptions.subqueryReadPreference = subqueryReadPreference;
|
||||
}
|
||||
preCount = (
|
||||
await rest.find(
|
||||
config,
|
||||
auth,
|
||||
className,
|
||||
where,
|
||||
preCountOptions,
|
||||
info.clientSDK,
|
||||
info.context
|
||||
)
|
||||
await rest.find(config, auth, className, where, preCountOptions, info.clientSDK, info.context)
|
||||
).count;
|
||||
if ((skip || 0) + limit < preCount) {
|
||||
skip = preCount - limit;
|
||||
@@ -158,11 +148,7 @@ const findObjects = async (
|
||||
|
||||
const options = {};
|
||||
|
||||
if (
|
||||
selectedFields.find(
|
||||
field => field.startsWith('edges.') || field.startsWith('pageInfo.')
|
||||
)
|
||||
) {
|
||||
if (selectedFields.find(field => field.startsWith('edges.') || field.startsWith('pageInfo.'))) {
|
||||
if (limit || limit === 0) {
|
||||
options.limit = limit;
|
||||
} else {
|
||||
@@ -181,9 +167,7 @@ const findObjects = async (
|
||||
}
|
||||
if (
|
||||
!needToGetAllKeys(
|
||||
parseClasses.find(
|
||||
({ className: parseClassName }) => className === parseClassName
|
||||
).fields,
|
||||
parseClasses.find(({ className: parseClassName }) => className === parseClassName).fields,
|
||||
keys,
|
||||
parseClasses
|
||||
)
|
||||
@@ -245,9 +229,7 @@ const findObjects = async (
|
||||
|
||||
pageInfo = {
|
||||
hasPreviousPage:
|
||||
((preCount && preCount > 0) || (count && count > 0)) &&
|
||||
skip !== undefined &&
|
||||
skip > 0,
|
||||
((preCount && preCount > 0) || (count && count > 0)) && skip !== undefined && skip > 0,
|
||||
startCursor: offsetToCursor(skip || 0),
|
||||
endCursor: offsetToCursor((skip || 0) + (results.length || 1) - 1),
|
||||
hasNextPage: (preCount || count) > (skip || 0) + results.length,
|
||||
@@ -261,14 +243,7 @@ const findObjects = async (
|
||||
};
|
||||
};
|
||||
|
||||
const calculateSkipAndLimit = (
|
||||
skipInput,
|
||||
first,
|
||||
after,
|
||||
last,
|
||||
before,
|
||||
maxLimit
|
||||
) => {
|
||||
const calculateSkipAndLimit = (skipInput, first, after, last, before, maxLimit) => {
|
||||
let skip = undefined;
|
||||
let limit = undefined;
|
||||
let needToPreCount = false;
|
||||
@@ -276,10 +251,7 @@ const calculateSkipAndLimit = (
|
||||
// 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'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Skip should be a positive number');
|
||||
}
|
||||
skip = skipInput;
|
||||
}
|
||||
@@ -288,10 +260,7 @@ const calculateSkipAndLimit = (
|
||||
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'
|
||||
);
|
||||
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
|
||||
@@ -301,10 +270,7 @@ const calculateSkipAndLimit = (
|
||||
// Validates the first param
|
||||
if (first || first === 0) {
|
||||
if (first < 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
'First should be a positive number'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'First should be a positive number');
|
||||
}
|
||||
|
||||
// The first param is translated to the limit param of the Parse legacy API
|
||||
@@ -316,10 +282,7 @@ const calculateSkipAndLimit = (
|
||||
// This method converts the cursor to the index of the object
|
||||
before = cursorToOffset(before);
|
||||
if ((!before && before !== 0) || before < 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
'Before is not a valid cursor'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Before is not a valid cursor');
|
||||
}
|
||||
|
||||
if ((skip || 0) >= before) {
|
||||
@@ -334,10 +297,7 @@ const calculateSkipAndLimit = (
|
||||
// Validates the last param
|
||||
if (last || last === 0) {
|
||||
if (last < 0) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
'Last should be a positive number'
|
||||
);
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Last should be a positive number');
|
||||
}
|
||||
|
||||
if (last > maxLimit) {
|
||||
|
||||
Reference in New Issue
Block a user