@@ -9857,7 +9857,7 @@ var QueryBuilder = /** @class */ (function () {
98579857 * @param {Model|string } model The model to use
98589858 * @param {boolean } multiple Determines whether plural/nodes syntax or singular syntax is used.
98599859 * @param {Arguments } args The args that will be passed to the query field ( user(role: $role) )
9860- * @param {Array<Model> } ignoreModels The models in this list are ignored (while traversing relations).
9860+ * @param {Array<Model> } ignoreRelations The models in this list are ignored (while traversing relations).
98619861 * Mainly for recursion
98629862 * @param {string } name Optional name of the field. If not provided, this will be the model name
98639863 * @param {boolean } allowIdFields Optional. Determines if id fields will be ignored for the argument generation.
@@ -9866,16 +9866,15 @@ var QueryBuilder = /** @class */ (function () {
98669866 *
98679867 * @todo Do we need the allowIdFields param?
98689868 */
9869- QueryBuilder . buildField = function ( model , multiple , args , ignoreModels , name , filter , allowIdFields ) {
9869+ QueryBuilder . buildField = function ( model , multiple , args , ignoreRelations , name , filter , allowIdFields ) {
98709870 if ( multiple === void 0 ) { multiple = true ; }
9871- if ( ignoreModels === void 0 ) { ignoreModels = [ ] ; }
9871+ if ( ignoreRelations === void 0 ) { ignoreRelations = [ ] ; }
98729872 if ( filter === void 0 ) { filter = false ; }
98739873 if ( allowIdFields === void 0 ) { allowIdFields = false ; }
98749874 var context = Context . getInstance ( ) ;
98759875 model = context . getModel ( model ) ;
9876- ignoreModels . push ( model ) ;
98779876 var params = this . buildArguments ( model , args , false , filter , allowIdFields ) ;
9878- var fields = "\n " + model . getQueryFields ( ) . join ( ' ' ) + "\n " + this . buildRelationsQuery ( model , ignoreModels ) + "\n " ;
9877+ var fields = "\n " + model . getQueryFields ( ) . join ( ' ' ) + "\n " + this . buildRelationsQuery ( model , ignoreRelations ) + "\n " ;
98799878 if ( multiple ) {
98809879 return "\n " + ( name ? name : model . pluralName ) + params + " {\n nodes {\n " + fields + "\n }\n }\n " ;
98819880 }
@@ -10026,14 +10025,12 @@ var QueryBuilder = /** @class */ (function () {
1002610025 * Generates the fields for all related models.
1002710026 *
1002810027 * @param {Model } model
10029- * @param {Array<Model> } ignoreModels The models in this list are ignored (while traversing relations).
10028+ * @param {Array<Model> } ignoreRelations The models in this list are ignored (while traversing relations).
1003010029 * @returns {string }
10031- *
10032- * @todo https://github.com/vuex-orm/vuex-orm-apollo/issues/13
1003310030 */
10034- QueryBuilder . buildRelationsQuery = function ( model , ignoreModels ) {
10031+ QueryBuilder . buildRelationsQuery = function ( model , ignoreRelations ) {
1003510032 var _this = this ;
10036- if ( ignoreModels === void 0 ) { ignoreModels = [ ] ; }
10033+ if ( ignoreRelations === void 0 ) { ignoreRelations = [ ] ; }
1003710034 if ( model === null )
1003810035 return '' ;
1003910036 var context = Context . getInstance ( ) ;
@@ -10051,22 +10048,25 @@ var QueryBuilder = /** @class */ (function () {
1005110048 context . logger . log ( 'WARNING: field has neither parent nor related property. Fallback to attribute name' , field ) ;
1005210049 }
1005310050 if ( model . shouldEagerLoadRelation ( field , relatedModel ) &&
10054- ! _this . shouldModelBeIgnored ( relatedModel , ignoreModels ) ) {
10051+ ! _this . shouldRelationBeIgnored ( model , relatedModel , ignoreRelations ) ) {
1005510052 var multiple = ! ( field instanceof context . components . BelongsTo ||
1005610053 field instanceof context . components . HasOne ) ;
10057- relationQueries . push ( _this . buildField ( relatedModel , multiple , undefined , ignoreModels , name , false ) ) ;
10054+ relationQueries . push ( _this . buildField ( relatedModel , multiple , undefined , ignoreRelations , name , false ) ) ;
10055+ ignoreRelations . push ( model . singularName + "." + relatedModel . singularName ) ;
1005810056 }
1005910057 } ) ;
1006010058 return relationQueries . join ( '\n' ) ;
1006110059 } ;
1006210060 /**
10063- * Tells if a model should be ignored because it's included in the ignoreModels array.
10061+ * Tells if a relation should be ignored because it's included in the ignoreRelations array.
1006410062 * @param {Model } model
10065- * @param {Array<Model> } ignoreModels
10063+ * @param {Model } relatedModel
10064+ * @param {Array<string> } ignoreRelations
1006610065 * @returns {boolean }
1006710066 */
10068- QueryBuilder . shouldModelBeIgnored = function ( model , ignoreModels ) {
10069- return ignoreModels . find ( function ( m ) { return m . singularName === model . singularName ; } ) !== undefined ;
10067+ QueryBuilder . shouldRelationBeIgnored = function ( model , relatedModel , ignoreRelations ) {
10068+ var relevantRelation = model . singularName + "." + relatedModel . singularName ;
10069+ return ignoreRelations . find ( function ( r ) { return r === relevantRelation ; } ) !== undefined ;
1007010070 } ;
1007110071 return QueryBuilder ;
1007210072} ( ) ) ;
0 commit comments