Skip to content

Commit 94e0053

Browse files
committed
Fix where by global id
1 parent 8edc480 commit 94e0053

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/GraphQL/helpers/objectsQueries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const findObjects = async (
6868
if (!where) {
6969
where = {};
7070
}
71-
transformQueryInputToParse(where, fields);
71+
transformQueryInputToParse(where, fields, className);
7272

7373
const options = {};
7474

src/GraphQL/transformers/query.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const transformQueryConstraintInputToParse = (
183183
});
184184
};
185185

186-
const transformQueryInputToParse = (constraints, fields) => {
186+
const transformQueryInputToParse = (constraints, fields, className) => {
187187
if (!constraints || typeof constraints !== 'object') {
188188
return;
189189
}
@@ -198,9 +198,30 @@ const transformQueryInputToParse = (constraints, fields) => {
198198

199199
if (fieldName !== 'objectId') {
200200
fieldValue.forEach(fieldValueItem => {
201-
transformQueryInputToParse(fieldValueItem, fields);
201+
transformQueryInputToParse(fieldValueItem, fields, className);
202202
});
203203
return;
204+
} else if (className) {
205+
Object.keys(fieldValue).forEach(constraintName => {
206+
const constraintValue = fieldValue[constraintName];
207+
if (typeof constraintValue === 'string') {
208+
const globalIdObject = fromGlobalId(constraintValue);
209+
210+
if (globalIdObject.type === className) {
211+
fieldValue[constraintName] = globalIdObject.id;
212+
}
213+
} else if (Array.isArray(constraintValue)) {
214+
fieldValue[constraintName] = constraintValue.map(value => {
215+
const globalIdObject = fromGlobalId(value);
216+
217+
if (globalIdObject.type === className) {
218+
return globalIdObject.id;
219+
}
220+
221+
return value;
222+
});
223+
}
224+
});
204225
}
205226
}
206227

0 commit comments

Comments
 (0)