Skip to content

Commit

Permalink
fix(api): fix header not sent to odoo
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoMunizOdoo committed Oct 21, 2023
1 parent fdd32d6 commit 0a0a26b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-api-client/src/setup/clientSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const buildClient = (settings: MiddlewareConfig) => {
fetch,
fetchOptions: settings.fetchOptions,
headers: {
Cookie: settings.sessionAuth,
Cookie: `session_id=${settings.sessionAuth}`,
'resquest-host': settings.requestHost,
'REAL-IP': settings.realIp
}
Expand Down
20 changes: 11 additions & 9 deletions playground-nuxt/app/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import { MutationName } from '~/server/mutations';
const { $sdk } = useNuxtApp();
const { data } = await $sdk().odoo.query<QueryProductVariantArgs, ProductVariantQueryResponse>({ queryName: QueryName.ProductVariantQuery }, {
productTemplateId: 39,
combinationId: [12, 305]
});
const go = async () => {
const { data } = await $sdk().odoo.mutation<MutationLoginArgs, LoginMutationResponse>({ mutationName: MutationName.LoginMutation }, {
email: "[email protected]",
password: "123"
});
console.log(data.productVariant.displayName);
console.log(data?.login);
const { data: dataMut } = await $sdk().odoo.mutation<MutationLoginArgs, LoginMutationResponse>({ mutationName: MutationName.LoginMutation }, {
email: "[email protected]",
password: "123"
});
const { data: asa } = await $sdk().odoo.query<QueryProductVariantArgs, ProductVariantQueryResponse>({ queryName: QueryName.LoadUserQuery }, {});
console.log(asa.productVariant.displayName);
};
</script>

<template>
<div>
<button @click="go">Go</button>
<MainBanner />

</div>
Expand Down
8 changes: 7 additions & 1 deletion playground-nuxt/app/server/api/odoo/mutation.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export default defineEventHandler(async (event) => {

const api: Endpoints = event.context.apolloClient.api;

return await api.mutation(body[0], body[1]);
const data = await api.mutation(body?.[0], body?.[1]);

if ((data.data as any)?.cookie) {
appendResponseHeader(event, 'Set-cookie', (data.data as any)?.cookie);
}

return data;
});

11 changes: 8 additions & 3 deletions playground-nuxt/app/server/api/odoo/query.post.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Endpoints } from '@erpgap/odoo-sdk-api-client';

export default cachedEventHandler(async (event) => {
export default defineEventHandler(async (event) => {
const body = await readBody(event);

const api: Endpoints = event.context.apolloClient.api;

return await api.query(body[0], body[1]);
const data = await api.query(body?.[0], body?.[1]);

if ((data.data as any)?.cookie) {
appendResponseHeader(event, 'Set-cookie', (data.data as any)?.cookie);
}

return data;
});

14 changes: 10 additions & 4 deletions playground-nuxt/app/server/middleware/apolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { createApiClient } from '@erpgap/odoo-sdk-api-client/server';
import { createApiClient } from '../../../../packages/sdk-api-client/src/index.server';
import { MiddlewareConfig } from '../../../../packages/sdk-api-client/src/index';
import { Queries } from '~/server/queries';
import { Mutations } from '~/server/mutations';

export default defineEventHandler((event) => {

event.context.apolloClient = createApiClient({
const config : MiddlewareConfig = {
odooGraphqlUrl: `${process.env.ODOO_BASE_URL}graphql/vsf`,
queries: { ...Queries, ...Mutations }
});
queries: { ...Queries, ...Mutations },
realIp: getRequestIP(event),
sessionAuth: parseCookies(event).session_id,
requestHost: getRequestHost(event)
};

event.context.apolloClient = createApiClient(config);
});

0 comments on commit 0a0a26b

Please sign in to comment.