@@ -7791,21 +7791,22 @@ var QueryBuilder = /** @class */ (function () {
7791
7791
* @param {Model|string } model The model to use
7792
7792
* @param {boolean } multiple Determines whether plural/nodes syntax or singular syntax is used.
7793
7793
* @param {Arguments } args The args that will be passed to the query field ( user(role: $role) )
7794
- * @param {Model } rootModel The model of the root query field. Used to avoid endless recursion
7794
+ * @param {Array< Model> } ignoreModels The models in this list are ignored (while traversing relations). Mainly for recursion
7795
7795
* @param {string } name Optional name of the field. If not provided, this will be the model name
7796
7796
* @param {boolean } allowIdFields Optional. Determines if id fields will be ignored for the argument generation.
7797
7797
* See buildArguments
7798
7798
* @returns {string }
7799
7799
*
7800
7800
* @todo Do we need the allowIdFields param?
7801
- * @todo There could be a endless recursion even with rootModel correctly set. We should track an array of models here probably?
7802
7801
*/
7803
- QueryBuilder . prototype . buildField = function ( model , multiple , args , rootModel , name , allowIdFields ) {
7802
+ QueryBuilder . prototype . buildField = function ( model , multiple , args , ignoreModels , name , allowIdFields ) {
7804
7803
if ( multiple === void 0 ) { multiple = true ; }
7804
+ if ( ignoreModels === void 0 ) { ignoreModels = [ ] ; }
7805
7805
if ( allowIdFields === void 0 ) { allowIdFields = false ; }
7806
7806
model = this . getModel ( model ) ;
7807
+ ignoreModels . push ( model ) ;
7807
7808
var params = this . buildArguments ( args , false , allowIdFields ) ;
7808
- var fields = "\n " + model . getQueryFields ( ) . join ( ' ' ) + "\n " + this . buildRelationsQuery ( model , rootModel ) + "\n " ;
7809
+ var fields = "\n " + model . getQueryFields ( ) . join ( ' ' ) + "\n " + this . buildRelationsQuery ( model , ignoreModels ) + "\n " ;
7809
7810
if ( multiple ) {
7810
7811
return "\n " + ( name ? name : model . pluralName ) + params + " {\n nodes {\n " + fields + "\n }\n }\n " ;
7811
7812
}
@@ -7842,7 +7843,7 @@ var QueryBuilder = /** @class */ (function () {
7842
7843
name = ( multiple ? model . pluralName : model . singularName ) ;
7843
7844
// build query
7844
7845
var query = type + " " + upcaseFirstLetter ( name ) + this . buildArguments ( args , true ) + " {\n" +
7845
- ( " " + this . buildField ( model , multiple , args , model , name , true ) + "\n" ) +
7846
+ ( " " + this . buildField ( model , multiple , args , [ ] , name , true ) + "\n" ) +
7846
7847
"}" ;
7847
7848
return src ( query ) ;
7848
7849
} ;
@@ -7979,28 +7980,33 @@ var QueryBuilder = /** @class */ (function () {
7979
7980
/**
7980
7981
*
7981
7982
* @param {Model } model
7982
- * @param {Model } rootModel
7983
+ * @param {Array< Model> } ignoreModels The models in this list are ignored (while traversing relations). Mainly for recursion
7983
7984
* @returns {Array<String> }
7984
7985
*/
7985
- QueryBuilder . prototype . buildRelationsQuery = function ( model , rootModel ) {
7986
+ QueryBuilder . prototype . buildRelationsQuery = function ( model , ignoreModels ) {
7986
7987
var _this = this ;
7988
+ if ( ignoreModels === void 0 ) { ignoreModels = [ ] ; }
7987
7989
if ( model === null )
7988
7990
return '' ;
7989
7991
var relationQueries = [ ] ;
7990
7992
model . getRelations ( ) . forEach ( function ( field , name ) {
7991
- if ( ! rootModel || ( name !== rootModel . singularName && name !== rootModel . pluralName ) ) {
7993
+ if ( ! _this . shouldModelBeIgnored ( _this . getModel ( name ) , ignoreModels ) ) {
7992
7994
var multiple = field . constructor . name !== 'BelongsTo' ;
7993
- relationQueries . push ( _this . buildField ( name , multiple , undefined , rootModel || model ) ) ;
7995
+ relationQueries . push ( _this . buildField ( name , multiple , undefined , ignoreModels ) ) ;
7994
7996
}
7995
7997
} ) ;
7996
7998
return relationQueries ;
7997
7999
} ;
8000
+ QueryBuilder . prototype . shouldModelBeIgnored = function ( model , ignoreModels ) {
8001
+ return ignoreModels . find ( function ( m ) { return m . singularName === model . singularName ; } ) !== undefined ;
8002
+ } ;
7998
8003
return QueryBuilder ;
7999
8004
} ( ) ) ;
8000
8005
8001
8006
var Logger = /** @class */ ( function ( ) {
8002
8007
function Logger ( enabled ) {
8003
8008
this . enabled = enabled ;
8009
+ this . log ( 'Logging is enabled.' ) ;
8004
8010
}
8005
8011
Logger . prototype . group = function ( ) {
8006
8012
var messages = [ ] ;
@@ -8024,7 +8030,7 @@ var Logger = /** @class */ (function () {
8024
8030
console . log . apply ( console , [ '[Vuex-ORM-Apollo]' ] . concat ( messages ) ) ;
8025
8031
}
8026
8032
} ;
8027
- Logger . prototype . logQuery = function ( query ) {
8033
+ Logger . prototype . logQuery = function ( query , variables ) {
8028
8034
if ( this . enabled ) {
8029
8035
try {
8030
8036
this . group ( 'Sending query:' ) ;
@@ -8034,6 +8040,8 @@ var Logger = /** @class */ (function () {
8034
8040
else {
8035
8041
console . log ( QueryBuilder . prettify ( query ) ) ;
8036
8042
}
8043
+ if ( variables )
8044
+ console . log ( 'VARIABLES:' , variables ) ;
8037
8045
this . groupEnd ( ) ;
8038
8046
}
8039
8047
catch ( e ) {
@@ -8329,6 +8337,7 @@ var VuexORMApollo = /** @class */ (function () {
8329
8337
return __generator ( this , function ( _a ) {
8330
8338
switch ( _a . label ) {
8331
8339
case 0 :
8340
+ this . logger . logQuery ( query , variables ) ;
8332
8341
if ( ! mutation ) return [ 3 /*break*/ , 2 ] ;
8333
8342
return [ 4 /*yield*/ , this . apolloClient . mutate ( { mutation : query , variables : variables } ) ] ;
8334
8343
case 1 :
0 commit comments