@@ -803,9 +803,6 @@ 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
- }
809
806
function valueToObjectRepresentation ( argObj , name , value , variables ) {
810
807
if ( isIntValue ( value ) || isFloatValue ( value ) ) {
811
808
argObj [ name . value ] = Number ( value . value ) ;
@@ -834,9 +831,6 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
834
831
else if ( isEnumValue ( value ) ) {
835
832
argObj [ name . value ] = value . value ;
836
833
}
837
- else if ( isNullValue ( value ) ) {
838
- argObj [ name . value ] = null ;
839
- }
840
834
else {
841
835
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." ) ;
842
836
}
@@ -865,14 +859,6 @@ function storeKeyNameFromField(field, variables) {
865
859
}
866
860
return getStoreKeyName ( field . name . value , argObj , directivesObj ) ;
867
861
}
868
- var KNOWN_DIRECTIVES = [
869
- 'connection' ,
870
- 'include' ,
871
- 'skip' ,
872
- 'client' ,
873
- 'rest' ,
874
- 'export' ,
875
- ] ;
876
862
function getStoreKeyName ( fieldName , args , directives ) {
877
863
if ( directives &&
878
864
directives [ 'connection' ] &&
@@ -894,24 +880,11 @@ function getStoreKeyName(fieldName, args, directives) {
894
880
return directives [ 'connection' ] [ 'key' ] ;
895
881
}
896
882
}
897
- var completeFieldName = fieldName ;
898
883
if ( args ) {
899
884
var stringifiedArgs = JSON . stringify ( args ) ;
900
- completeFieldName += "(" + stringifiedArgs + ")" ;
885
+ return fieldName + "(" + stringifiedArgs + ")" ;
901
886
}
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
- } ) ;
913
- }
914
- return completeFieldName ;
887
+ return fieldName ;
915
888
}
916
889
function argumentsObjectFromField ( field , variables ) {
917
890
if ( field . arguments && field . arguments . length ) {
@@ -983,7 +956,7 @@ function shouldInclude(selection, variables) {
983
956
var evaledValue = false ;
984
957
if ( ! ifValue || ifValue . kind !== 'BooleanValue' ) {
985
958
if ( ifValue . kind !== 'Variable' ) {
986
- throw new Error ( "Argument for the @" + directiveName + " directive must be a variable or a boolean value." ) ;
959
+ throw new Error ( "Argument for the @" + directiveName + " directive must be a variable or a bool ean value." ) ;
987
960
}
988
961
else {
989
962
evaledValue = variables [ ifValue . name . value ] ;
@@ -1230,24 +1203,6 @@ var TYPENAME_FIELD = {
1230
1203
value : '__typename' ,
1231
1204
} ,
1232
1205
} ;
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
- }
1251
1206
function addTypenameToSelectionSet ( selectionSet , isRoot ) {
1252
1207
if ( isRoot === void 0 ) { isRoot = false ; }
1253
1208
if ( selectionSet . selections ) {
@@ -1285,10 +1240,15 @@ function removeDirectivesFromSelectionSet(directives, selectionSet) {
1285
1240
! selection ||
1286
1241
! selection . directives )
1287
1242
return selection ;
1288
- var directiveMatcher = getDirectiveMatcher ( directives ) ;
1289
1243
var remove ;
1290
1244
selection . directives = selection . directives . filter ( function ( directive ) {
1291
- var shouldKeep = ! directiveMatcher ( 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
+ } ) ;
1292
1252
if ( ! remove && ! shouldKeep && agressiveRemove )
1293
1253
remove = true ;
1294
1254
return shouldKeep ;
@@ -1311,7 +1271,14 @@ function removeDirectivesFromDocument(directives, doc) {
1311
1271
} ) ;
1312
1272
var operation = getOperationDefinitionOrDie ( docClone ) ;
1313
1273
var fragments = createFragmentMap ( getFragmentDefinitions ( docClone ) ) ;
1314
- return isNotEmpty ( operation , fragments ) ? docClone : null ;
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 ;
1315
1282
}
1316
1283
var added$1 = new Map ( ) ;
1317
1284
function addTypenameToDocument ( doc ) {
@@ -7896,8 +7863,8 @@ var QueryBuilder = /** @class */ (function () {
7896
7863
if ( args ) {
7897
7864
Object . keys ( args ) . forEach ( function ( key ) {
7898
7865
var value = args [ key ] ;
7899
- // Ignore ids and connections
7900
- if ( ! ( value instanceof Array || ( key === 'id' && ! allowIdFields ) ) ) {
7866
+ // Ignore null fields, ids and connections
7867
+ if ( value && ! ( value instanceof Array || ( key === 'id' && ! allowIdFields ) ) ) {
7901
7868
var typeOrValue = '' ;
7902
7869
if ( signature ) {
7903
7870
if ( typeof value === 'object' && value . __type ) {
@@ -7939,10 +7906,11 @@ var QueryBuilder = /** @class */ (function () {
7939
7906
return '' ;
7940
7907
var relationQueries = [ ] ;
7941
7908
model . getRelations ( ) . forEach ( function ( field , name ) {
7942
- var relatedModel = _this . getModel ( name ) ;
7909
+ var relatedModel = _this . getModel ( field . related ? field . related . name : name ) ;
7943
7910
if ( _this . shouldEagerLoadRelation ( model , field , relatedModel ) &&
7944
7911
! _this . shouldModelBeIgnored ( relatedModel , ignoreModels ) ) {
7945
- var multiple = ! ( field instanceof _this . context . components . BelongsTo ) ;
7912
+ var multiple = ! ( field instanceof _this . context . components . BelongsTo ||
7913
+ field instanceof _this . context . components . HasOne ) ;
7946
7914
relationQueries . push ( _this . buildField ( relatedModel , multiple , undefined , ignoreModels ) ) ;
7947
7915
}
7948
7916
} ) ;
@@ -8102,7 +8070,7 @@ var Context = /** @class */ (function () {
8102
8070
*/
8103
8071
Context . prototype . getModel = function ( model ) {
8104
8072
if ( typeof model === 'string' ) {
8105
- var name_1 = inflection$2 . singularize ( model ) ;
8073
+ var name_1 = inflection$2 . singularize ( downcaseFirstLetter ( model ) ) ;
8106
8074
model = this . models . get ( name_1 ) ;
8107
8075
if ( ! model )
8108
8076
throw new Error ( "No such model " + name_1 + "!" ) ;
0 commit comments