Commit b27a0fde authored by LAVENIER's avatar LAVENIER
Browse files

Release v0.13.0

[fix] GraphQL: fix cache update (update 'total' in query result)
parent 385d2192
{
"name": "@sumaris-net/ngx-components",
"description": "SUMARiS Angular components",
"version": "0.12.1",
"version": "0.13.0",
"author": "contact@e-is.pro",
"license": "AGPL-3.0",
"readmeFilename": "README.md",
......
......@@ -101,6 +101,10 @@ export class GraphqlService {
return this.apollo.client.cache;
}
get defaultFetchPolicy(): WatchQueryFetchPolicy {
return this._defaultFetchPolicy;
}
constructor(
private platform: Platform,
private apollo: Apollo,
......
import { GraphqlService, MutateQueryOptions, WatchQueryOptions } from '../graphql/graphql.service';
import { Page } from '../../shared/services/entity-service.class';
import { EmptyObject } from 'apollo-angular/types';
import { Observable } from 'rxjs';
import { FetchResult } from '@apollo/client/link/core';
import { EntityUtils } from './model/entity.model';
import { ApolloCache, InternalRefetchQueriesInclude } from '@apollo/client/core';
import { isNotEmptyArray, isNotNil, toBoolean } from '../../shared/functions';
import { environment } from '../../../environments/environment';
import { Directive, Optional } from '@angular/core';
import { QueryRef } from 'apollo-angular';
import { PureQueryOptions } from '@apollo/client/core/types';
import { DocumentNode } from 'graphql';
import {GraphqlService, MutateQueryOptions, WatchQueryOptions} from '../graphql/graphql.service';
import {Page} from '../../shared/services/entity-service.class';
import {EmptyObject} from 'apollo-angular/types';
import {Observable} from 'rxjs';
import {FetchResult} from '@apollo/client/link/core';
import {EntityUtils} from './model/entity.model';
import {ApolloCache, InternalRefetchQueriesInclude} from '@apollo/client/core';
import {isNotEmptyArray, isNotNil, toBoolean} from '../../shared/functions';
import {environment} from '../../../environments/environment';
import {Directive, Optional} from '@angular/core';
import {QueryRef} from 'apollo-angular';
import {PureQueryOptions} from '@apollo/client/core/types';
import {DocumentNode} from 'graphql';
const sha256 = require('hash.js/lib/hash/sha/256');
......@@ -87,10 +87,19 @@ export abstract class BaseGraphqlService<T = any, F = any, ID = any> {
}
mutableWatchQuery<D, V = EmptyObject>(opts: MutableWatchQueryOptions<D, T, V>): Observable<D> {
opts.fetchPolicy = opts.fetchPolicy || this.graphql.defaultFetchPolicy;
// Standard query (no cache)
if (opts.fetchPolicy === 'no-cache') {
return this.graphql.watchQuery(opts);
}
// No arrayFieldName
if (!opts.arrayFieldName) {
if (this._debug) console.warn(this._logPrefix + '̀Missing \'opts.arrayFieldName\' : unable to create a mutable watch query');
return this.graphql.watchQuery(opts);
}
// Create the query id
const queryId = this.computeMutableWatchQueryId(opts);
const exactMatchQueries = this._mutableWatchQueries.filter(q => q.id === queryId);
......@@ -104,8 +113,9 @@ export abstract class BaseGraphqlService<T = any, F = any, ID = any> {
queryRef = mutableQuery.queryRef;
if (this._debug) console.debug(this._logPrefix + `Find same mutable watch query (same variables) {${queryId}}. Skip register`);
// Refetch if need
if (opts.fetchPolicy && (opts.fetchPolicy === 'network-only' || opts.fetchPolicy === 'no-cache' || opts.fetchPolicy === 'cache-and-network')) {
// Refetch if need data from network
if (opts.fetchPolicy === 'network-only' || opts.fetchPolicy === 'cache-and-network') {
console.warn(this._logPrefix + ' Mutable query already exists, and fetchPolicy=' + opts.fetchPolicy + '. Force refetch query...');
queryRef.refetch(mutableQuery.variables);
}
//if (mutableQuery.counter > 3) {
......@@ -120,6 +130,7 @@ export abstract class BaseGraphqlService<T = any, F = any, ID = any> {
queryRef,
variables: opts.variables,
arrayFieldName: opts.arrayFieldName,
totalFieldName: opts.totalFieldName,
insertFilterFn: opts.insertFilterFn,
sortFn: opts.sortFn,
counter: 1
......@@ -146,6 +157,7 @@ export abstract class BaseGraphqlService<T = any, F = any, ID = any> {
query: query.query,
variables: query.variables,
arrayFieldName: query.arrayFieldName as string,
totalFieldName: query.totalFieldName as string,
sortFn: query.sortFn,
data
});
......@@ -158,6 +170,7 @@ export abstract class BaseGraphqlService<T = any, F = any, ID = any> {
query: query.query,
variables: query.variables,
arrayFieldName: query.arrayFieldName as string,
totalFieldName: query.totalFieldName as string,
sortFn: query.sortFn,
data: opts.data
});
......
......@@ -996,7 +996,7 @@ export abstract class AppTable<
}
// DEBUG
console.debug("[table] Detect click on row");
//console.debug("[table] Detect click on row");
if (row.id === -1 || row.editing) return true; // Already in edition
if (event?.defaultPrevented) return false; // Cancelled by event
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment