Skip to content

Commit

Permalink
feat: add query type without middleware cache
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMunizOdoo committed Feb 27, 2024
1 parent 8063ae9 commit 96d2237
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-api-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erpgap/odoo-sdk-api-client",
"version": "0.5.0",
"version": "0.6.0",
"private": false,
"sideEffects": false,
"server": "server/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erpgap/odoo-sdk",
"version": "0.5.0",
"version": "0.6.0",
"private": false,
"main": "lib/index.cjs.js",
"module": "lib/index.es.js",
Expand Down
12 changes: 11 additions & 1 deletion packages/sdk/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Methods = typeof methods;
export const odooConnector = (options: Options): Methods => {
let mutation = null;
let query = null;
let queryNoCache = null;

mutation = async <ApiParams, ApiResponseType>(metadata: MutationMetadataParams, params?: ApiParams): Promise<ApiResponseType> => {
return await client.post('mutation', [metadata, params]);
Expand All @@ -25,6 +26,10 @@ export const odooConnector = (options: Options): Methods => {
return await client.post('query', [metadata, params]);
};

queryNoCache = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> =>{
return await client.post('query=no-cache', [metadata, params]);
};

if (options.ofetch) {
mutation = async <ApiParams, ApiResponseType>(metadata: MutationMetadataParams, params?: ApiParams): Promise<ApiResponseType> => {
return await options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache' });
Expand All @@ -34,9 +39,14 @@ export const odooConnector = (options: Options): Methods => {
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);
};

queryNoCache = async <ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> =>{
const cacheKey = metadata.cacheKey || hash({ ...metadata, ...params });
return await options.ofetch('/api/odoo/query-no-cache', { method: 'POST', body: [metadata, params], cache: 'no-cache', key: cacheKey } as any);
};
}

client.defaults.baseURL = options.apiUrl;

return { query, mutation };
return { query, mutation, queryNoCache };
};
1 change: 1 addition & 0 deletions packages/sdk/src/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './query';
export * from './query-no-cache';
export * from './mutation';
12 changes: 12 additions & 0 deletions packages/sdk/src/methods/query-no-cache/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApolloQueryResult } from '@apollo/client';
import { QueryMetadataParams, Endpoints } from '@erpgap/odoo-sdk-api-client';
import { client } from '../../client';

/**
* Make the query
*
* @example
*/
export async function queryNoCache<ApiParams, ApiResponseType>(metadata: QueryMetadataParams, params?: ApiParams): Promise<ApiResponseType> {
return await client.post('query-no-cache', [metadata, params]);
}
1 change: 0 additions & 1 deletion packages/sdk/src/methods/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ApolloQueryResult } from '@apollo/client';
import { QueryMetadataParams, Endpoints } from '@erpgap/odoo-sdk-api-client';
import { client } from '../../client';

Expand Down

0 comments on commit 96d2237

Please sign in to comment.