@sumaris-net/ngx-components 18.20.1 → 18.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20582,6 +20582,8 @@ class GraphqlService extends StartableService {
20582
20582
  }
20583
20583
  const res = await firstValueFrom(this.apollo
20584
20584
  .mutate({
20585
+ refetchQueries: opts?.refetchQueries,
20586
+ awaitRefetchQueries: opts?.awaitRefetchQueries,
20585
20587
  mutation: opts.mutation,
20586
20588
  variables: opts.variables,
20587
20589
  context: opts.context,
@@ -21276,8 +21278,8 @@ class BaseGraphqlService extends StartableService {
21276
21278
  }
21277
21279
  insertIntoMutableCachedQueries(cache, opts) {
21278
21280
  const queries = this.findMutableWatchQueries(opts);
21279
- if (!queries.length)
21280
- return;
21281
+ if (isEmptyArray(queries))
21282
+ return; // No query found
21281
21283
  queries.forEach((query) => {
21282
21284
  if (Array.isArray(opts.data)) {
21283
21285
  // Filter values, if a filter function exists
@@ -21365,26 +21367,20 @@ class BaseGraphqlService extends StartableService {
21365
21367
  return [queryName, opts.arrayFieldName, variablesKey].join('|');
21366
21368
  }
21367
21369
  findMutableWatchQueries(opts) {
21368
- // Search by queryName
21369
- if (opts.queryName) {
21370
- return this._mutableWatchQueries.filter((q) => q.id.startsWith(opts.queryName + '|'));
21371
- }
21372
- if (opts.queryNames) {
21373
- return (opts.queryNames
21370
+ // Search by query names
21371
+ const queryNames = opts.queryName ? [opts.queryName] : opts.queryNames;
21372
+ if (queryNames) {
21373
+ return queryNames
21374
21374
  .map((queryName) => this._mutableWatchQueries.filter((q) => q.id.startsWith(queryName + '|')))
21375
- // flatMap
21376
- .reduce((res, array) => res.concat(...array), []));
21375
+ .flat();
21377
21376
  }
21378
- // Search by query
21379
- if (opts.query) {
21380
- return this._mutableWatchQueries.filter((q) => q.query === opts.query);
21381
- }
21382
- if (opts.queries) {
21383
- return (opts.queries
21377
+ // Search by query objects
21378
+ const queries = opts.query ? [opts.query] : opts.queries;
21379
+ if (queries) {
21380
+ return queries
21384
21381
  .filter(isNotNil)
21385
21382
  .map((query) => this._mutableWatchQueries.filter((q) => q.query === query))
21386
- // flatMap
21387
- .reduce((res, array) => res.concat(...array), []));
21383
+ .flat();
21388
21384
  }
21389
21385
  throw Error('Invalid options: only one property must be set');
21390
21386
  }
@@ -25436,6 +25432,7 @@ class BaseEntityService extends BaseGraphqlService {
25436
25432
  defaultSortBy;
25437
25433
  defaultSortDirection;
25438
25434
  watchQueriesUpdatePolicy;
25435
+ watchQueriesDeletePolicy;
25439
25436
  get defaultFetchPolicy() {
25440
25437
  return this.graphql.defaultFetchPolicy;
25441
25438
  }
@@ -25453,6 +25450,7 @@ class BaseEntityService extends BaseGraphqlService {
25453
25450
  this.defaultSortBy = options.defaultSortBy || 'id';
25454
25451
  this.defaultSortDirection = options.defaultSortDirection || 'asc';
25455
25452
  this.watchQueriesUpdatePolicy = options.watchQueriesUpdatePolicy || 'update-cache';
25453
+ this.watchQueriesDeletePolicy = options.watchQueriesDeletePolicy || 'refetch-queries';
25456
25454
  const obj = new dataType();
25457
25455
  this._typename = obj.__typename || 'UnknownVO';
25458
25456
  this._logTypeName = removeEnd(this._typename, 'VO');
@@ -25634,6 +25632,7 @@ class BaseEntityService extends BaseGraphqlService {
25634
25632
  });
25635
25633
  }
25636
25634
  }
25635
+ // Call update function, if any
25637
25636
  if (opts?.update) {
25638
25637
  opts.update(cache, { data }, { context, variables });
25639
25638
  }
@@ -25683,6 +25682,7 @@ class BaseEntityService extends BaseGraphqlService {
25683
25682
  data: savedEntity,
25684
25683
  });
25685
25684
  }
25685
+ // Call update function, if any
25686
25686
  if (opts?.update) {
25687
25687
  opts.update(cache, { data }, { context, variables });
25688
25688
  }
@@ -25713,13 +25713,13 @@ class BaseEntityService extends BaseGraphqlService {
25713
25713
  console.debug(this._logPrefix + `Deleting ${this._logTypeName}...`, ids);
25714
25714
  await this.graphql.mutate({
25715
25715
  mutation: this.mutations.deleteAll,
25716
- refetchQueries: this.getRefetchQueriesForMutation(opts),
25716
+ refetchQueries: this.getRefetchQueriesForMutation({ policy: this.watchQueriesDeletePolicy, ...opts }),
25717
25717
  awaitRefetchQueries: opts && opts.awaitRefetchQueries,
25718
25718
  variables: { ids },
25719
25719
  error: { code: ErrorCodes.DELETE_DATA_ERROR, message: 'ERROR.DELETE_DATA_ERROR' },
25720
25720
  update: (cache, res) => {
25721
25721
  // Remove from cache
25722
- if (this.watchQueriesUpdatePolicy === 'update-cache') {
25722
+ if (this.watchQueriesDeletePolicy === 'update-cache') {
25723
25723
  this.removeFromMutableCachedQueriesByIds(cache, {
25724
25724
  queries: this.getLoadQueries(),
25725
25725
  ids,
@@ -25752,13 +25752,13 @@ class BaseEntityService extends BaseGraphqlService {
25752
25752
  console.debug(this._logPrefix + `Deleting ${this._logTypeName} {${id}}...`);
25753
25753
  await this.graphql.mutate({
25754
25754
  mutation: this.mutations.delete,
25755
- refetchQueries: this.getRefetchQueriesForMutation(opts),
25755
+ refetchQueries: this.getRefetchQueriesForMutation({ policy: this.watchQueriesDeletePolicy, ...opts }),
25756
25756
  awaitRefetchQueries: opts && opts.awaitRefetchQueries,
25757
25757
  variables: { id },
25758
25758
  error: { code: ErrorCodes.DELETE_DATA_ERROR, message: 'ERROR.DELETE_DATA_ERROR' },
25759
25759
  update: (proxy, res) => {
25760
25760
  // Remove from cache
25761
- if (this.watchQueriesUpdatePolicy === 'update-cache') {
25761
+ if (this.watchQueriesDeletePolicy === 'update-cache') {
25762
25762
  this.removeFromMutableCachedQueriesByIds(proxy, {
25763
25763
  queries: this.getLoadQueries(),
25764
25764
  ids: [id],
@@ -25867,13 +25867,14 @@ class BaseEntityService extends BaseGraphqlService {
25867
25867
  return source.asObject(opts);
25868
25868
  }
25869
25869
  getRefetchQueriesForMutation(opts) {
25870
- if (opts && opts.refetchQueries)
25870
+ if (opts?.refetchQueries)
25871
25871
  return opts.refetchQueries;
25872
25872
  // Skip if update policy not used refecth queries
25873
- if (this.watchQueriesUpdatePolicy !== 'refetch-queries')
25873
+ const watchQueriesPolicy = opts?.policy ?? this.watchQueriesUpdatePolicy;
25874
+ if (watchQueriesPolicy !== 'refetch-queries')
25874
25875
  return undefined;
25875
25876
  const queries = this.getLoadQueries();
25876
- if (!queries.length)
25877
+ if (isEmptyArray(queries))
25877
25878
  return undefined; // Skip if empty
25878
25879
  // Find the refetch queries definition
25879
25880
  return this.findRefetchQueries({ queries });