@@ -10102,6 +10102,7 @@ var Context = /** @class */ (function () {
10102
10102
return Context ;
10103
10103
} ( ) ) ;
10104
10104
10105
+ var inflection$3 = require ( 'inflection' ) ;
10105
10106
/**
10106
10107
* Contains all logic to build GraphQL queries/mutations.
10107
10108
*/
@@ -10114,24 +10115,26 @@ var QueryBuilder = /** @class */ (function () {
10114
10115
* @param {Model|string } model The model to use
10115
10116
* @param {boolean } multiple Determines whether plural/nodes syntax or singular syntax is used.
10116
10117
* @param {Arguments } args The args that will be passed to the query field ( user(role: $role) )
10117
- * @param {Array<Model> } ignoreRelations The models in this list are ignored (while traversing relations).
10118
+ * @param {Array<Model> } path The relations in this list are ignored (while traversing relations).
10118
10119
* Mainly for recursion
10119
10120
* @param {string } name Optional name of the field. If not provided, this will be the model name
10121
+ * @param filter
10120
10122
* @param {boolean } allowIdFields Optional. Determines if id fields will be ignored for the argument generation.
10121
10123
* See buildArguments
10122
10124
* @returns {string }
10123
10125
*
10124
10126
* @todo Do we need the allowIdFields param?
10125
10127
*/
10126
- QueryBuilder . buildField = function ( model , multiple , args , ignoreRelations , name , filter , allowIdFields ) {
10128
+ QueryBuilder . buildField = function ( model , multiple , args , path , name , filter , allowIdFields ) {
10127
10129
if ( multiple === void 0 ) { multiple = true ; }
10128
- if ( ignoreRelations === void 0 ) { ignoreRelations = [ ] ; }
10130
+ if ( path === void 0 ) { path = [ ] ; }
10129
10131
if ( filter === void 0 ) { filter = false ; }
10130
10132
if ( allowIdFields === void 0 ) { allowIdFields = false ; }
10131
10133
var context = Context . getInstance ( ) ;
10132
10134
model = context . getModel ( model ) ;
10133
10135
var params = this . buildArguments ( model , args , false , filter , allowIdFields ) ;
10134
- var fields = "\n " + model . getQueryFields ( ) . join ( ' ' ) + "\n " + this . buildRelationsQuery ( model , ignoreRelations ) + "\n " ;
10136
+ path = path . length === 0 ? [ model . singularName ] : path ;
10137
+ var fields = "\n " + model . getQueryFields ( ) . join ( ' ' ) + "\n " + this . buildRelationsQuery ( model , path ) + "\n " ;
10135
10138
if ( multiple ) {
10136
10139
var header = "" + ( name ? name : model . pluralName ) + params ;
10137
10140
if ( context . connectionQueryMode === 'nodes' ) {
@@ -10297,12 +10300,12 @@ var QueryBuilder = /** @class */ (function () {
10297
10300
* Generates the fields for all related models.
10298
10301
*
10299
10302
* @param {Model } model
10300
- * @param {Array<Model> } ignoreRelations The models in this list are ignored (while traversing relations).
10303
+ * @param {Array<Model> } path
10301
10304
* @returns {string }
10302
10305
*/
10303
- QueryBuilder . buildRelationsQuery = function ( model , ignoreRelations ) {
10306
+ QueryBuilder . buildRelationsQuery = function ( model , path ) {
10304
10307
var _this = this ;
10305
- if ( ignoreRelations === void 0 ) { ignoreRelations = [ ] ; }
10308
+ if ( path === void 0 ) { path = [ ] ; }
10306
10309
if ( model === null )
10307
10310
return '' ;
10308
10311
var context = Context . getInstance ( ) ;
@@ -10319,29 +10322,19 @@ var QueryBuilder = /** @class */ (function () {
10319
10322
relatedModel = context . getModel ( name ) ;
10320
10323
context . logger . log ( 'WARNING: field has neither parent nor related property. Fallback to attribute name' , field ) ;
10321
10324
}
10322
- if ( model . shouldEagerLoadRelation ( name , field , relatedModel ) &&
10323
- ! _this . shouldRelationBeIgnored ( model , relatedModel , ignoreRelations ) ) {
10325
+ var singularizedFieldName = inflection$3 . singularize ( name ) ;
10326
+ var ignore = path . includes ( singularizedFieldName ) ;
10327
+ // console.log(`-----> Will ${ignore ? '' : 'not'} ignore ${model.singularName}.${name}, path: ${path.join('.')}`);
10328
+ if ( model . shouldEagerLoadRelation ( name , field , relatedModel ) && ! ignore ) {
10324
10329
var multiple = ! ( field instanceof context . components . BelongsTo ||
10325
10330
field instanceof context . components . HasOne ) ;
10326
- ignoreRelations . push ( model . singularName + "." + relatedModel . singularName ) ;
10327
- relationQueries . push ( _this . buildField ( relatedModel , multiple , undefined , ignoreRelations , name , false ) ) ;
10331
+ var newPath = path . slice ( 0 ) ;
10332
+ newPath . push ( singularizedFieldName ) ;
10333
+ relationQueries . push ( _this . buildField ( relatedModel , multiple , undefined , newPath , name , false ) ) ;
10328
10334
}
10329
10335
} ) ;
10330
10336
return relationQueries . join ( '\n' ) ;
10331
10337
} ;
10332
- /**
10333
- * Tells if a relation should be ignored because it's included in the ignoreRelations array.
10334
- * @param {Model } model
10335
- * @param {Model } relatedModel
10336
- * @param {Array<string> } ignoreRelations
10337
- * @returns {boolean }
10338
- */
10339
- QueryBuilder . shouldRelationBeIgnored = function ( model , relatedModel , ignoreRelations ) {
10340
- var relevantRelation = model . singularName + "." + relatedModel . singularName ;
10341
- return ignoreRelations . find ( function ( r ) {
10342
- return r === relevantRelation ;
10343
- } ) !== undefined ;
10344
- } ;
10345
10338
return QueryBuilder ;
10346
10339
} ( ) ) ;
10347
10340
@@ -10495,7 +10488,7 @@ var __generator$3 = (undefined && undefined.__generator) || function (thisArg, b
10495
10488
if ( op [ 0 ] & 5 ) throw op [ 1 ] ; return { value : op [ 0 ] ? op [ 1 ] : void 0 , done : true } ;
10496
10489
}
10497
10490
} ;
10498
- var inflection$3 = require ( 'inflection' ) ;
10491
+ var inflection$4 = require ( 'inflection' ) ;
10499
10492
/**
10500
10493
* Base class for all Vuex actions. Contains some utility and convenience methods.
10501
10494
*/
@@ -10592,7 +10585,7 @@ var Action = /** @class */ (function () {
10592
10585
Object . keys ( args ) . forEach ( function ( key ) {
10593
10586
var value = args [ key ] ;
10594
10587
if ( value instanceof context . components . Model ) {
10595
- var model = context . getModel ( inflection$3 . singularize ( value . $self ( ) . entity ) ) ;
10588
+ var model = context . getModel ( inflection$4 . singularize ( value . $self ( ) . entity ) ) ;
10596
10589
var transformedValue = Transformer . transformOutgoingData ( model , value ) ;
10597
10590
context . logger . log ( 'A' , key , 'model was found within the variables and will be transformed from' , value , 'to' , transformedValue ) ;
10598
10591
args [ key ] = transformedValue ;
0 commit comments