Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL: Change Order Enum Strategy #6515

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/GraphQL/helpers/objectsQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ const needToGetAllKeys = (fields, keys) =>
? !!keys.split(',').find(keyName => !fields[keyName.split('.')[0]])
: true;

const transformOrder = order =>
order
.map(o => {
const direction = o.indexOf('_ASC') > 0 ? '_ASC' : '_DESC';
let field = o.replace(direction, '');
field = field === 'id' ? 'objectId' : field;
if (direction === '_ASC') {
return `${field}`;
} else {
return `-${field}`;
}
})
.join(',');

const getObject = async (
className,
objectId,
Expand Down Expand Up @@ -130,7 +144,7 @@ const findObjects = async (
}
if (options.limit !== 0) {
if (order) {
options.order = order;
options.order = transformOrder(order);
}
if (skip) {
options.skip = skip;
Expand Down
3 changes: 1 addition & 2 deletions src/GraphQL/loaders/parseClassQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,11 @@ const load = function(
.filter(field => field.startsWith('edges.node.'))
.map(field => field.replace('edges.node.', ''))
);
const parseOrder = order && order.join(',');

return await objectsQueries.findObjects(
className,
where,
parseOrder,
order,
skip,
first,
after,
Expand Down
8 changes: 3 additions & 5 deletions src/GraphQL/loaders/parseClassTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,11 @@ const load = (
const updatedSortFields = {
...sortFields,
};
const value = field === 'id' ? 'objectId' : field;
if (asc) {
updatedSortFields[`${field}_ASC`] = { value };
updatedSortFields[`${field}_ASC`] = {};
}
if (desc) {
updatedSortFields[`${field}_DESC`] = { value: `-${value}` };
updatedSortFields[`${field}_DESC`] = {};
}
return updatedSortFields;
}, {}),
Expand Down Expand Up @@ -434,7 +433,6 @@ const load = (
.filter(field => field.startsWith('edges.node.'))
.map(field => field.replace('edges.node.', ''))
);
const parseOrder = order && order.join(',');

return objectsQueries.findObjects(
source[field].className,
Expand All @@ -449,7 +447,7 @@ const load = (
},
...(where || {}),
},
parseOrder,
order,
skip,
first,
after,
Expand Down