@@ -241,12 +241,13 @@ function transformQueryKeyValue(className, key, value, schema) {
241
241
schema . fields [ key ] &&
242
242
schema . fields [ key ] . type === 'Pointer' ;
243
243
244
+ const field = schema && schema . fields [ key ] ;
244
245
if ( expectedTypeIsPointer || ! schema && value && value . __type === 'Pointer' ) {
245
246
key = '_p_' + key ;
246
247
}
247
248
248
249
// Handle query constraints
249
- const transformedConstraint = transformConstraint ( value , expectedTypeIsArray ) ;
250
+ const transformedConstraint = transformConstraint ( value , field ) ;
250
251
if ( transformedConstraint !== CannotTransform ) {
251
252
if ( transformedConstraint . $text ) {
252
253
return { key : '$text' , value : transformedConstraint . $text } ;
@@ -454,7 +455,7 @@ const addLegacyACL = restObject => {
454
455
// cannot perform a transformation
455
456
function CannotTransform ( ) { }
456
457
457
- const transformInteriorAtom = atom => {
458
+ const transformInteriorAtom = ( atom ) => {
458
459
// TODO: check validity harder for the __type-defined types
459
460
if ( typeof atom === 'object' && atom && ! ( atom instanceof Date ) && atom . __type === 'Pointer' ) {
460
461
return {
@@ -480,14 +481,17 @@ const transformInteriorAtom = atom => {
480
481
// or arrays with generic stuff inside.
481
482
// Raises an error if this cannot possibly be valid REST format.
482
483
// Returns CannotTransform if it's just not an atom
483
- function transformTopLevelAtom ( atom ) {
484
+ function transformTopLevelAtom ( atom , field ) {
484
485
switch ( typeof atom ) {
485
- case 'string' :
486
486
case 'number' :
487
487
case 'boolean' :
488
- return atom ;
489
488
case 'undefined' :
490
489
return atom ;
490
+ case 'string' :
491
+ if ( field && field . type === 'Pointer' ) {
492
+ return `${ field . targetClass } $${ atom } ` ;
493
+ }
494
+ return atom ;
491
495
case 'symbol' :
492
496
case 'function' :
493
497
throw new Parse . Error ( Parse . Error . INVALID_JSON , `cannot transform value: ${ atom } ` ) ;
@@ -534,13 +538,14 @@ function transformTopLevelAtom(atom) {
534
538
// If it is not a valid constraint but it could be a valid something
535
539
// else, return CannotTransform.
536
540
// inArray is whether this is an array field.
537
- function transformConstraint ( constraint , inArray ) {
541
+ function transformConstraint ( constraint , field ) {
542
+ const inArray = field && field . type && field . type === 'Array' ;
538
543
if ( typeof constraint !== 'object' || ! constraint ) {
539
544
return CannotTransform ;
540
545
}
541
546
const transformFunction = inArray ? transformInteriorAtom : transformTopLevelAtom ;
542
547
const transformer = ( atom ) => {
543
- const result = transformFunction ( atom ) ;
548
+ const result = transformFunction ( atom , field ) ;
544
549
if ( result === CannotTransform ) {
545
550
throw new Parse . Error ( Parse . Error . INVALID_JSON , `bad atom: ${ JSON . stringify ( atom ) } ` ) ;
546
551
}
0 commit comments