This repository was archived by the owner on Apr 17, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ export const createOptimisticResponse = (options: OptimisticOptions) => {
6363 ...mappedVariables ,
6464 optimisticResponse : true
6565 } ;
66- if ( operationType === CacheOperation . ADD ) {
66+ if ( operationType === CacheOperation . ADD && ! optimisticResponse [ operation ] [ idField ] ) {
6767 optimisticResponse [ operation ] [ idField ] = generateClientId ( ) ;
6868 }
6969
Original file line number Diff line number Diff line change @@ -28,6 +28,37 @@ test("check that createNewOptimisticResponse is properly composed with name prop
2828 expect ( result . createItem . name ) . toBe ( "test" ) ;
2929} ) ;
3030
31+ test ( "ids are not overwritten for add operations if one is supplied" , ( ) => {
32+ const options : OptimisticOptions = {
33+ mutation : CREATE_ITEM ,
34+ operationType : CacheOperation . ADD ,
35+ returnType : "Test" ,
36+ variables : {
37+ id : "123" ,
38+ name : "test"
39+ }
40+ } ;
41+ const result = createOptimisticResponse ( options ) ;
42+ expect ( result . createItem . id ) . toBe ( "123" ) ;
43+ expect ( result . createItem . name ) . toBe ( "test" ) ;
44+ } ) ;
45+
46+ test ( "ids are not overwritten for add operations if one is supplied" , ( ) => {
47+ const options : OptimisticOptions = {
48+ mutation : CREATE_ITEM ,
49+ operationType : CacheOperation . ADD ,
50+ idField : "customId" ,
51+ returnType : "Test" ,
52+ variables : {
53+ customId : "123" ,
54+ name : "test"
55+ }
56+ } ;
57+ const result = createOptimisticResponse ( options ) ;
58+ expect ( result . createItem . customId ) . toBe ( "123" ) ;
59+ expect ( result . createItem . name ) . toBe ( "test" ) ;
60+ } ) ;
61+
3162test ( "check that createNewOptimisticResponse is without id" , ( ) => {
3263 const options : OptimisticOptions = {
3364 mutation : CREATE_ITEM ,
You can’t perform that action at this time.
0 commit comments