@@ -803,6 +803,9 @@ function isListValue(value) {
803
803
function isEnumValue ( value ) {
804
804
return value . kind === 'EnumValue' ;
805
805
}
806
+ function isNullValue ( value ) {
807
+ return value . kind === 'NullValue' ;
808
+ }
806
809
function valueToObjectRepresentation ( argObj , name , value , variables ) {
807
810
if ( isIntValue ( value ) || isFloatValue ( value ) ) {
808
811
argObj [ name . value ] = Number ( value . value ) ;
@@ -831,6 +834,9 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
831
834
else if ( isEnumValue ( value ) ) {
832
835
argObj [ name . value ] = value . value ;
833
836
}
837
+ else if ( isNullValue ( value ) ) {
838
+ argObj [ name . value ] = null ;
839
+ }
834
840
else {
835
841
throw new Error ( "The inline argument \"" + name . value + "\" of kind \"" + value . kind + "\" is not supported.\n Use variables instead of inline arguments to overcome this limitation." ) ;
836
842
}
@@ -859,6 +865,14 @@ function storeKeyNameFromField(field, variables) {
859
865
}
860
866
return getStoreKeyName ( field . name . value , argObj , directivesObj ) ;
861
867
}
868
+ var KNOWN_DIRECTIVES = [
869
+ 'connection' ,
870
+ 'include' ,
871
+ 'skip' ,
872
+ 'client' ,
873
+ 'rest' ,
874
+ 'export' ,
875
+ ] ;
862
876
function getStoreKeyName ( fieldName , args , directives ) {
863
877
if ( directives &&
864
878
directives [ 'connection' ] &&
@@ -880,11 +894,24 @@ function getStoreKeyName(fieldName, args, directives) {
880
894
return directives [ 'connection' ] [ 'key' ] ;
881
895
}
882
896
}
897
+ var completeFieldName = fieldName ;
883
898
if ( args ) {
884
899
var stringifiedArgs = JSON . stringify ( args ) ;
885
- return fieldName + "(" + stringifiedArgs + ")" ;
900
+ completeFieldName += "(" + stringifiedArgs + ")" ;
901
+ }
902
+ if ( directives ) {
903
+ Object . keys ( directives ) . forEach ( function ( key ) {
904
+ if ( KNOWN_DIRECTIVES . indexOf ( key ) !== - 1 )
905
+ return ;
906
+ if ( directives [ key ] && Object . keys ( directives [ key ] ) . length ) {
907
+ completeFieldName += "@" + key + "(" + JSON . stringify ( directives [ key ] ) + ")" ;
908
+ }
909
+ else {
910
+ completeFieldName += "@" + key ;
911
+ }
912
+ } ) ;
886
913
}
887
- return fieldName ;
914
+ return completeFieldName ;
888
915
}
889
916
function argumentsObjectFromField ( field , variables ) {
890
917
if ( field . arguments && field . arguments . length ) {
@@ -956,7 +983,7 @@ function shouldInclude(selection, variables) {
956
983
var evaledValue = false ;
957
984
if ( ! ifValue || ifValue . kind !== 'BooleanValue' ) {
958
985
if ( ifValue . kind !== 'Variable' ) {
959
- throw new Error ( "Argument for the @" + directiveName + " directive must be a variable or a bool ean value." ) ;
986
+ throw new Error ( "Argument for the @" + directiveName + " directive must be a variable or a boolean value." ) ;
960
987
}
961
988
else {
962
989
evaledValue = variables [ ifValue . name . value ] ;
@@ -1203,6 +1230,24 @@ var TYPENAME_FIELD = {
1203
1230
value : '__typename' ,
1204
1231
} ,
1205
1232
} ;
1233
+ function isNotEmpty ( op , fragments ) {
1234
+ return ( op . selectionSet . selections . filter ( function ( selectionSet ) {
1235
+ return ! ( selectionSet &&
1236
+ selectionSet . kind === 'FragmentSpread' &&
1237
+ ! isNotEmpty ( fragments [ selectionSet . name . value ] , fragments ) ) ;
1238
+ } ) . length > 0 ) ;
1239
+ }
1240
+ function getDirectiveMatcher ( directives ) {
1241
+ return function directiveMatcher ( directive ) {
1242
+ return directives . some ( function ( dir ) {
1243
+ if ( dir . name && dir . name === directive . name . value )
1244
+ return true ;
1245
+ if ( dir . test && dir . test ( directive ) )
1246
+ return true ;
1247
+ return false ;
1248
+ } ) ;
1249
+ } ;
1250
+ }
1206
1251
function addTypenameToSelectionSet ( selectionSet , isRoot ) {
1207
1252
if ( isRoot === void 0 ) { isRoot = false ; }
1208
1253
if ( selectionSet . selections ) {
@@ -1240,15 +1285,10 @@ function removeDirectivesFromSelectionSet(directives, selectionSet) {
1240
1285
! selection ||
1241
1286
! selection . directives )
1242
1287
return selection ;
1288
+ var directiveMatcher = getDirectiveMatcher ( directives ) ;
1243
1289
var remove ;
1244
1290
selection . directives = selection . directives . filter ( function ( directive ) {
1245
- var shouldKeep = ! directives . some ( function ( dir ) {
1246
- if ( dir . name && dir . name === directive . name . value )
1247
- return true ;
1248
- if ( dir . test && dir . test ( directive ) )
1249
- return true ;
1250
- return false ;
1251
- } ) ;
1291
+ var shouldKeep = ! directiveMatcher ( directive ) ;
1252
1292
if ( ! remove && ! shouldKeep && agressiveRemove )
1253
1293
remove = true ;
1254
1294
return shouldKeep ;
@@ -1271,14 +1311,7 @@ function removeDirectivesFromDocument(directives, doc) {
1271
1311
} ) ;
1272
1312
var operation = getOperationDefinitionOrDie ( docClone ) ;
1273
1313
var fragments = createFragmentMap ( getFragmentDefinitions ( docClone ) ) ;
1274
- var isNotEmpty = function ( op ) {
1275
- return op . selectionSet . selections . filter ( function ( selectionSet ) {
1276
- return ! ( selectionSet &&
1277
- selectionSet . kind === 'FragmentSpread' &&
1278
- ! isNotEmpty ( fragments [ selectionSet . name . value ] ) ) ;
1279
- } ) . length > 0 ;
1280
- } ;
1281
- return isNotEmpty ( operation ) ? docClone : null ;
1314
+ return isNotEmpty ( operation , fragments ) ? docClone : null ;
1282
1315
}
1283
1316
var added$1 = new Map ( ) ;
1284
1317
function addTypenameToDocument ( doc ) {
@@ -8223,20 +8256,21 @@ var VuexORMApollo = /** @class */ (function () {
8223
8256
*/
8224
8257
VuexORMApollo . prototype . persist = function ( _a , _b ) {
8225
8258
var state = _a . state , dispatch = _a . dispatch ;
8226
- var id = _b . id ;
8259
+ var id = _b . id , args = _b . args ;
8227
8260
return __awaiter ( this , void 0 , void 0 , function ( ) {
8228
- var model , data , variables , mutationName , _c ;
8229
- return __generator ( this , function ( _d ) {
8230
- switch ( _d . label ) {
8261
+ var model , data , mutationName ;
8262
+ return __generator ( this , function ( _c ) {
8263
+ switch ( _c . label ) {
8231
8264
case 0 :
8232
8265
if ( ! id ) return [ 3 /*break*/ , 2 ] ;
8233
8266
model = this . context . getModel ( state . $name ) ;
8234
8267
data = model . baseModel . getters ( 'find' ) ( id ) ;
8235
- variables = ( _c = { } , _c [ model . singularName ] = this . queryBuilder . transformOutgoingData ( data ) , _c ) ;
8268
+ args = args || { } ;
8269
+ args [ model . singularName ] = this . queryBuilder . transformOutgoingData ( data ) ;
8236
8270
mutationName = "create" + upcaseFirstLetter ( model . singularName ) ;
8237
- return [ 4 /*yield*/ , this . mutate ( mutationName , variables , dispatch , model , false ) ] ;
8271
+ return [ 4 /*yield*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8238
8272
case 1 :
8239
- _d . sent ( ) ;
8273
+ _c . sent ( ) ;
8240
8274
// TODO is this really necessary?
8241
8275
return [ 2 /*return*/ , model . baseModel . getters ( 'find' ) ( id ) ] ;
8242
8276
case 2 : return [ 2 /*return*/ ] ;
@@ -8284,21 +8318,21 @@ var VuexORMApollo = /** @class */ (function () {
8284
8318
*/
8285
8319
VuexORMApollo . prototype . push = function ( _a , _b ) {
8286
8320
var state = _a . state , dispatch = _a . dispatch ;
8287
- var data = _b . data ;
8321
+ var data = _b . data , args = _b . args ;
8288
8322
return __awaiter ( this , void 0 , void 0 , function ( ) {
8289
- var model , variables , mutationName , _c ;
8290
- return __generator ( this , function ( _d ) {
8291
- switch ( _d . label ) {
8323
+ var model , mutationName ;
8324
+ return __generator ( this , function ( _c ) {
8325
+ switch ( _c . label ) {
8292
8326
case 0 :
8293
8327
if ( ! data ) return [ 3 /*break*/ , 2 ] ;
8294
8328
model = this . context . getModel ( state . $name ) ;
8295
- variables = ( _c = {
8296
- id : data . id
8297
- } , _c [ model . singularName ] = this . queryBuilder . transformOutgoingData ( data ) , _c ) ;
8329
+ args = args || { } ;
8330
+ args [ 'id' ] = data . id ;
8331
+ args [ model . singularName ] = this . queryBuilder . transformOutgoingData ( data ) ;
8298
8332
mutationName = "update" + upcaseFirstLetter ( model . singularName ) ;
8299
- return [ 4 /*yield*/ , this . mutate ( mutationName , variables , dispatch , model , false ) ] ;
8333
+ return [ 4 /*yield*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8300
8334
case 1 :
8301
- _d . sent ( ) ;
8335
+ _c . sent ( ) ;
8302
8336
// TODO is this really necessary?
8303
8337
return [ 2 /*return*/ , model . baseModel . getters ( 'find' ) ( data . id ) ] ;
8304
8338
case 2 : return [ 2 /*return*/ ] ;
@@ -8316,14 +8350,16 @@ var VuexORMApollo = /** @class */ (function () {
8316
8350
*/
8317
8351
VuexORMApollo . prototype . destroy = function ( _a , _b ) {
8318
8352
var state = _a . state , dispatch = _a . dispatch ;
8319
- var id = _b . id ;
8353
+ var id = _b . id , args = _b . args ;
8320
8354
return __awaiter ( this , void 0 , void 0 , function ( ) {
8321
8355
var model , mutationName ;
8322
8356
return __generator ( this , function ( _c ) {
8323
8357
if ( id ) {
8324
8358
model = this . context . getModel ( state . $name ) ;
8325
8359
mutationName = "delete" + upcaseFirstLetter ( model . singularName ) ;
8326
- return [ 2 /*return*/ , this . mutate ( mutationName , { id : id } , dispatch , model , false ) ] ;
8360
+ args = args || { } ;
8361
+ args [ 'id' ] = id ;
8362
+ return [ 2 /*return*/ , this . mutate ( mutationName , args , dispatch , model , false ) ] ;
8327
8363
}
8328
8364
return [ 2 /*return*/ ] ;
8329
8365
} ) ;
0 commit comments