@@ -6606,6 +6606,162 @@ describe('ParseGraphQLServer', () => {
66066606            ) ; 
66076607          } ) ; 
66086608        } ) ; 
6609+ 
6610+         it ( 'should unset fields when null used on update/create' ,  async  ( )  =>  { 
6611+           const  customerSchema  =  new  Parse . Schema ( 'Customer' ) ; 
6612+           customerSchema . addString ( 'aString' ) ; 
6613+           customerSchema . addBoolean ( 'aBoolean' ) ; 
6614+           customerSchema . addDate ( 'aDate' ) ; 
6615+           customerSchema . addArray ( 'aArray' ) ; 
6616+           customerSchema . addGeoPoint ( 'aGeoPoint' ) ; 
6617+           customerSchema . addPointer ( 'aPointer' ,  'Customer' ) ; 
6618+           customerSchema . addObject ( 'aObject' ) ; 
6619+           customerSchema . addPolygon ( 'aPolygon' ) ; 
6620+           await  customerSchema . save ( ) ; 
6621+ 
6622+           await  parseGraphQLServer . parseGraphQLSchema . schemaCache . clear ( ) ; 
6623+ 
6624+           const  cus  =  new  Parse . Object ( 'Customer' ) ; 
6625+           await  cus . save ( {  aString : 'hello'  } ) ; 
6626+ 
6627+           const  fields  =  { 
6628+             aString : "i'm string" , 
6629+             aBoolean : true , 
6630+             aDate : new  Date ( ) . toISOString ( ) , 
6631+             aArray : [ 'hello' ,  1 ] , 
6632+             aGeoPoint : {  latitude : 30 ,  longitude : 30  } , 
6633+             aPointer : {  link : cus . id  } , 
6634+             aObject : {  prop : {  subprop : 1  } ,  prop2 : 'test'  } , 
6635+             aPolygon : [ 
6636+               {  latitude : 30 ,  longitude : 30  } , 
6637+               {  latitude : 31 ,  longitude : 31  } , 
6638+               {  latitude : 32 ,  longitude : 32  } , 
6639+               {  latitude : 30 ,  longitude : 30  } , 
6640+             ] , 
6641+           } ; 
6642+           const  nullFields  =  Object . keys ( fields ) . reduce ( ( acc ,  k )  =>  ( {  ...acc ,  [ k ] : null  } ) ,  { } ) ; 
6643+           const  result  =  await  apolloClient . mutate ( { 
6644+             mutation : gql ` 
6645+               mutation CreateCustomer($input: CreateCustomerInput!) { 
6646+                 createCustomer(input: $input) { 
6647+                   customer { 
6648+                     id 
6649+                     aString 
6650+                     aBoolean 
6651+                     aDate 
6652+                     aArray { 
6653+                       ... on Element { 
6654+                         value 
6655+                       } 
6656+                     } 
6657+                     aGeoPoint { 
6658+                       longitude 
6659+                       latitude 
6660+                     } 
6661+                     aPointer { 
6662+                       objectId 
6663+                     } 
6664+                     aObject 
6665+                     aPolygon { 
6666+                       longitude 
6667+                       latitude 
6668+                     } 
6669+                   } 
6670+                 } 
6671+               } 
6672+             ` , 
6673+             variables : { 
6674+               input : {  fields } , 
6675+             } , 
6676+           } ) ; 
6677+           const  { 
6678+             data : { 
6679+               createCustomer : { 
6680+                 customer : {  aPointer,  aArray,  id,  ...otherFields  } , 
6681+               } , 
6682+             } , 
6683+           }  =  result ; 
6684+           expect ( id ) . toBeDefined ( ) ; 
6685+           delete  otherFields . __typename ; 
6686+           delete  otherFields . aGeoPoint . __typename ; 
6687+           otherFields . aPolygon . forEach ( v  =>  { 
6688+             delete  v . __typename ; 
6689+           } ) ; 
6690+           expect ( { 
6691+             ...otherFields , 
6692+             aPointer : {  link : aPointer . objectId  } , 
6693+             aArray : aArray . map ( ( {  value } )  =>  value ) , 
6694+           } ) . toEqual ( fields ) ; 
6695+ 
6696+           const  updated  =  await  apolloClient . mutate ( { 
6697+             mutation : gql ` 
6698+               mutation UpdateCustomer($input: UpdateCustomerInput!) { 
6699+                 updateCustomer(input: $input) { 
6700+                   customer { 
6701+                     aString 
6702+                     aBoolean 
6703+                     aDate 
6704+                     aArray { 
6705+                       ... on Element { 
6706+                         value 
6707+                       } 
6708+                     } 
6709+                     aGeoPoint { 
6710+                       longitude 
6711+                       latitude 
6712+                     } 
6713+                     aPointer { 
6714+                       objectId 
6715+                     } 
6716+                     aObject 
6717+                     aPolygon { 
6718+                       longitude 
6719+                       latitude 
6720+                     } 
6721+                   } 
6722+                 } 
6723+               } 
6724+             ` , 
6725+             variables : { 
6726+               input : {  fields : nullFields ,  id } , 
6727+             } , 
6728+           } ) ; 
6729+           const  { 
6730+             data : { 
6731+               updateCustomer : {  customer } , 
6732+             } , 
6733+           }  =  updated ; 
6734+           delete  customer . __typename ; 
6735+           expect ( Object . keys ( customer ) . length ) . toEqual ( 8 ) ; 
6736+           Object . keys ( customer ) . forEach ( k  =>  { 
6737+             expect ( customer [ k ] ) . toBeNull ( ) ; 
6738+           } ) ; 
6739+           try  { 
6740+             const  queryResult  =  await  apolloClient . query ( { 
6741+               query : gql ` 
6742+                 query getEmptyCustomer($where: CustomerWhereInput!) { 
6743+                   customers(where: $where) { 
6744+                     edges { 
6745+                       node { 
6746+                         id 
6747+                       } 
6748+                     } 
6749+                   } 
6750+                 } 
6751+               ` , 
6752+               variables : { 
6753+                 where : Object . keys ( fields ) . reduce ( 
6754+                   ( acc ,  k )  =>  ( {  ...acc ,  [ k ] : {  exists : false  }  } ) , 
6755+                   { } 
6756+                 ) , 
6757+               } , 
6758+             } ) ; 
6759+ 
6760+             expect ( queryResult . data . customers . edges . length ) . toEqual ( 1 ) ; 
6761+           }  catch  ( e )  { 
6762+             console . log ( JSON . stringify ( e ) ) ; 
6763+           } 
6764+         } ) ; 
66096765      } ) ; 
66106766
66116767      describe ( 'Files Mutations' ,  ( )  =>  { 
@@ -9141,7 +9297,7 @@ describe('ParseGraphQLServer', () => {
91419297            const  mutationResult  =  await  apolloClient . mutate ( { 
91429298              mutation : gql ` 
91439299                mutation UnlinkFile($id: ID!) { 
9144-                   updateSomeClass(input: { id: $id, fields: { someField: { file:  null }  } }) { 
9300+                   updateSomeClass(input: { id: $id, fields: { someField: null } }) { 
91459301                    someClass { 
91469302                      someField { 
91479303                        name 
0 commit comments