@@ -241,12 +241,13 @@ function transformQueryKeyValue(className, key, value, schema) {
241241 schema . fields [ key ] &&
242242 schema . fields [ key ] . type === 'Pointer' ;
243243
244+ const field = schema && schema . fields [ key ] ;
244245 if ( expectedTypeIsPointer || ! schema && value && value . __type === 'Pointer' ) {
245246 key = '_p_' + key ;
246247 }
247248
248249 // Handle query constraints
249- const transformedConstraint = transformConstraint ( value , expectedTypeIsArray ) ;
250+ const transformedConstraint = transformConstraint ( value , field ) ;
250251 if ( transformedConstraint !== CannotTransform ) {
251252 if ( transformedConstraint . $text ) {
252253 return { key : '$text' , value : transformedConstraint . $text } ;
@@ -454,7 +455,7 @@ const addLegacyACL = restObject => {
454455// cannot perform a transformation
455456function CannotTransform ( ) { }
456457
457- const transformInteriorAtom = atom => {
458+ const transformInteriorAtom = ( atom ) => {
458459 // TODO: check validity harder for the __type-defined types
459460 if ( typeof atom === 'object' && atom && ! ( atom instanceof Date ) && atom . __type === 'Pointer' ) {
460461 return {
@@ -480,14 +481,17 @@ const transformInteriorAtom = atom => {
480481// or arrays with generic stuff inside.
481482// Raises an error if this cannot possibly be valid REST format.
482483// Returns CannotTransform if it's just not an atom
483- function transformTopLevelAtom ( atom ) {
484+ function transformTopLevelAtom ( atom , field ) {
484485 switch ( typeof atom ) {
485- case 'string' :
486486 case 'number' :
487487 case 'boolean' :
488- return atom ;
489488 case 'undefined' :
490489 return atom ;
490+ case 'string' :
491+ if ( field && field . type === 'Pointer' ) {
492+ return `${ field . targetClass } $${ atom } ` ;
493+ }
494+ return atom ;
491495 case 'symbol' :
492496 case 'function' :
493497 throw new Parse . Error ( Parse . Error . INVALID_JSON , `cannot transform value: ${ atom } ` ) ;
@@ -534,13 +538,14 @@ function transformTopLevelAtom(atom) {
534538// If it is not a valid constraint but it could be a valid something
535539// else, return CannotTransform.
536540// 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' ;
538543 if ( typeof constraint !== 'object' || ! constraint ) {
539544 return CannotTransform ;
540545 }
541546 const transformFunction = inArray ? transformInteriorAtom : transformTopLevelAtom ;
542547 const transformer = ( atom ) => {
543- const result = transformFunction ( atom ) ;
548+ const result = transformFunction ( atom , field ) ;
544549 if ( result === CannotTransform ) {
545550 throw new Parse . Error ( Parse . Error . INVALID_JSON , `bad atom: ${ JSON . stringify ( atom ) } ` ) ;
546551 }
0 commit comments