@@ -7791,21 +7791,22 @@ var QueryBuilder = /** @class */ (function () {
77917791 * @param {Model|string } model The model to use
77927792 * @param {boolean } multiple Determines whether plural/nodes syntax or singular syntax is used.
77937793 * @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
77957795 * @param {string } name Optional name of the field. If not provided, this will be the model name
77967796 * @param {boolean } allowIdFields Optional. Determines if id fields will be ignored for the argument generation.
77977797 * See buildArguments
77987798 * @returns {string }
77997799 *
78007800 * @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?
78027801 */
7803- QueryBuilder . prototype . buildField = function ( model , multiple , args , rootModel , name , allowIdFields ) {
7802+ QueryBuilder . prototype . buildField = function ( model , multiple , args , ignoreModels , name , allowIdFields ) {
78047803 if ( multiple === void 0 ) { multiple = true ; }
7804+ if ( ignoreModels === void 0 ) { ignoreModels = [ ] ; }
78057805 if ( allowIdFields === void 0 ) { allowIdFields = false ; }
78067806 model = this . getModel ( model ) ;
7807+ ignoreModels . push ( model ) ;
78077808 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 " ;
78097810 if ( multiple ) {
78107811 return "\n " + ( name ? name : model . pluralName ) + params + " {\n nodes {\n " + fields + "\n }\n }\n " ;
78117812 }
@@ -7842,7 +7843,7 @@ var QueryBuilder = /** @class */ (function () {
78427843 name = ( multiple ? model . pluralName : model . singularName ) ;
78437844 // build query
78447845 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" ) +
78467847 "}" ;
78477848 return src ( query ) ;
78487849 } ;
@@ -7979,28 +7980,33 @@ var QueryBuilder = /** @class */ (function () {
79797980 /**
79807981 *
79817982 * @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
79837984 * @returns {Array<String> }
79847985 */
7985- QueryBuilder . prototype . buildRelationsQuery = function ( model , rootModel ) {
7986+ QueryBuilder . prototype . buildRelationsQuery = function ( model , ignoreModels ) {
79867987 var _this = this ;
7988+ if ( ignoreModels === void 0 ) { ignoreModels = [ ] ; }
79877989 if ( model === null )
79887990 return '' ;
79897991 var relationQueries = [ ] ;
79907992 model . getRelations ( ) . forEach ( function ( field , name ) {
7991- if ( ! rootModel || ( name !== rootModel . singularName && name !== rootModel . pluralName ) ) {
7993+ if ( ! _this . shouldModelBeIgnored ( _this . getModel ( name ) , ignoreModels ) ) {
79927994 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 ) ) ;
79947996 }
79957997 } ) ;
79967998 return relationQueries ;
79977999 } ;
8000+ QueryBuilder . prototype . shouldModelBeIgnored = function ( model , ignoreModels ) {
8001+ return ignoreModels . find ( function ( m ) { return m . singularName === model . singularName ; } ) !== undefined ;
8002+ } ;
79988003 return QueryBuilder ;
79998004} ( ) ) ;
80008005
80018006var Logger = /** @class */ ( function ( ) {
80028007 function Logger ( enabled ) {
80038008 this . enabled = enabled ;
8009+ this . log ( 'Logging is enabled.' ) ;
80048010 }
80058011 Logger . prototype . group = function ( ) {
80068012 var messages = [ ] ;
@@ -8024,7 +8030,7 @@ var Logger = /** @class */ (function () {
80248030 console . log . apply ( console , [ '[Vuex-ORM-Apollo]' ] . concat ( messages ) ) ;
80258031 }
80268032 } ;
8027- Logger . prototype . logQuery = function ( query ) {
8033+ Logger . prototype . logQuery = function ( query , variables ) {
80288034 if ( this . enabled ) {
80298035 try {
80308036 this . group ( 'Sending query:' ) ;
@@ -8034,6 +8040,8 @@ var Logger = /** @class */ (function () {
80348040 else {
80358041 console . log ( QueryBuilder . prettify ( query ) ) ;
80368042 }
8043+ if ( variables )
8044+ console . log ( 'VARIABLES:' , variables ) ;
80378045 this . groupEnd ( ) ;
80388046 }
80398047 catch ( e ) {
@@ -8329,6 +8337,7 @@ var VuexORMApollo = /** @class */ (function () {
83298337 return __generator ( this , function ( _a ) {
83308338 switch ( _a . label ) {
83318339 case 0 :
8340+ this . logger . logQuery ( query , variables ) ;
83328341 if ( ! mutation ) return [ 3 /*break*/ , 2 ] ;
83338342 return [ 4 /*yield*/ , this . apolloClient . mutate ( { mutation : query , variables : variables } ) ] ;
83348343 case 1 :
0 commit comments