From 8063ae96dd8015f1ce26641daa6f2e801018c4db Mon Sep 17 00:00:00 2001 From: Leonardo Muniz Date: Thu, 28 Dec 2023 22:33:42 -0300 Subject: [PATCH] fix: fix query automatic cache from useFetch --- packages/sdk-api-client/package.json | 4 ++-- packages/sdk-api-client/src/index.server.ts | 1 - packages/sdk/package.json | 4 ++-- packages/sdk/src/connector.ts | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/sdk-api-client/package.json b/packages/sdk-api-client/package.json index 94fe6beb..18c278ad 100644 --- a/packages/sdk-api-client/package.json +++ b/packages/sdk-api-client/package.json @@ -1,6 +1,6 @@ { "name": "@erpgap/odoo-sdk-api-client", - "version": "0.4.9", + "version": "0.5.0", "private": false, "sideEffects": false, "server": "server/index.js", @@ -43,4 +43,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/sdk-api-client/src/index.server.ts b/packages/sdk-api-client/src/index.server.ts index db08b599..1db69808 100644 --- a/packages/sdk-api-client/src/index.server.ts +++ b/packages/sdk-api-client/src/index.server.ts @@ -5,7 +5,6 @@ import sessionHeaderExtension from './extensions/sessionHeaderExtension '; import * as apiEndpoints from './api'; const onCreate = (settings: MiddlewareConfig) => { - const client = buildClient(settings); return { diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 43078c06..d8825a77 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@erpgap/odoo-sdk", - "version": "0.4.9", + "version": "0.5.0", "private": false, "main": "lib/index.cjs.js", "module": "lib/index.es.js", @@ -41,4 +41,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/sdk/src/connector.ts b/packages/sdk/src/connector.ts index 657dd528..20c55dc4 100644 --- a/packages/sdk/src/connector.ts +++ b/packages/sdk/src/connector.ts @@ -1,10 +1,9 @@ import { client } from './client'; import { Options } from './types'; import * as methods from './methods/index'; -import { FetchResult } from '@apollo/client'; import { MutationMetadataParams } from '../../sdk-api-client'; -import { ApolloQueryResult } from '@apollo/client'; import { QueryMetadataParams } from '../../sdk-api-client'; +import hash from 'object-hash'; /** * Connector methods. @@ -32,7 +31,8 @@ export const odooConnector = (options: Options): Methods => { }; query = async (metadata: QueryMetadataParams, params?: ApiParams): Promise =>{ - return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache' }); + const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params }); + return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey } as any); }; }