diff --git a/docs/tips copy/customTypes.md b/docs/tips copy/customTypes.md deleted file mode 100755 index fe40c4e5..00000000 --- a/docs/tips copy/customTypes.md +++ /dev/null @@ -1,26 +0,0 @@ -# Custom types -If the project need a custom type, try to extend the base type. - -::: tip Odoo Convetion -projectName + type - camelCase -::: - -## Example - -```js -import { Product, Category } from '@vue-storefront/odoo-api'; - -// Project name = BlueBrothers - -export interface BlueBrothersProduct extends Product { - strangeLabel?: string, - acessories?: Accessory[] - ... -} - -export interface BlueBrothersCategory extends Category { - subCategory?: BlueBrothersCategory - ... -} - -``` diff --git a/docs/tips copy/i18n.md b/docs/tips copy/i18n.md deleted file mode 100755 index 85d8f371..00000000 --- a/docs/tips copy/i18n.md +++ /dev/null @@ -1,15 +0,0 @@ -# i18n -Always register the string on en.json or other language files whhen you -use $t(''). WHY ? - - -- Don't pollute the console of browser -- Speed up the building process -- Speed up the CI building process - -### Tools to automate / speed up - -- [i18n Manager](https://www.electronjs.org/apps/i18n-manager) -- [VsCode Ally](https://marketplace.visualstudio.com/items?itemName=Lokalise.i18n-ally) - - diff --git a/packages/nuxt-layer/server/middleware/apolloClient.ts b/packages/nuxt-layer/server/middleware/apolloClient.ts index e0389f66..6e48cf41 100644 --- a/packages/nuxt-layer/server/middleware/apolloClient.ts +++ b/packages/nuxt-layer/server/middleware/apolloClient.ts @@ -5,7 +5,6 @@ import { Mutations } from '~/server/mutations'; export default defineEventHandler((event) => { const config : MiddlewareConfig = { - // https://odoo-cla.ce.promptequation.com/graphql/vsf odooGraphqlUrl: `${process.env.ODOO_BASE_URL}graphql/vsf`, queries: { ...Queries, ...Mutations }, headers: { diff --git a/packages/sdk-api-client/src/api/query/index.ts b/packages/sdk-api-client/src/api/query/index.ts index aca2fe20..c837856a 100644 --- a/packages/sdk-api-client/src/api/query/index.ts +++ b/packages/sdk-api-client/src/api/query/index.ts @@ -3,22 +3,22 @@ import consola from 'consola'; export const query: Endpoints['query'] = async (context: OdooIntegrationContext, metadata: QueryMetadataParams, params?: ApiParams) => { - if(!metadata || !metadata.queryName) { - const msg = 'Developer Error: queryName is required' + if (!metadata || !metadata.queryName) { + const msg = 'Developer Error: queryName is required'; consola.error(msg); throw msg; } - if(!context.config.queries || Object.keys(context.config?.queries)?.length == 0) { - const msg = 'Developer Error: queries must be configured (MiddlewareConfig.queries)' + if (!context.config.queries || Object.keys(context.config?.queries)?.length == 0) { + const msg = 'Developer Error: queries must be configured (MiddlewareConfig.queries)'; consola.error(msg); throw msg; } const query = context.config.queries[metadata.queryName]; - if(!query) { - const msg = `Developer Error: query ${metadata.queryName} is not configured in middleware` + if (!query) { + const msg = `Developer Error: query ${metadata.queryName} is not configured in middleware`; consola.error(msg); throw msg; } diff --git a/packages/sdk-api-client/src/setup/clientSetup.ts b/packages/sdk-api-client/src/setup/clientSetup.ts index d51ff69b..27418563 100644 --- a/packages/sdk-api-client/src/setup/clientSetup.ts +++ b/packages/sdk-api-client/src/setup/clientSetup.ts @@ -1,23 +1,11 @@ import { ApolloClient, ApolloLink, InMemoryCache, createHttpLink } from '@apollo/client'; -import { onError } from "@apollo/client/link/error"; import { MiddlewareConfig } from '../index'; -import consola from 'consola'; import fetch from 'cross-fetch'; const buildClient = (settings: MiddlewareConfig) => { - const errorLink = onError(({ graphQLErrors, networkError, operation }) => { - if (graphQLErrors) { - graphQLErrors.map((error) => consola.error({label: '[GRAPHQL ERROR]', ...error, operation })); - } - - if (networkError) { - consola.error({ label: '[NETWORK ERROR]', message: networkError }); - } - }); - const httpLink = createHttpLink({ uri: settings.odooGraphqlUrl, credentials: 'include', @@ -40,7 +28,6 @@ const buildClient = (settings: MiddlewareConfig) => { }); const apolloLink = ApolloLink.from([ - errorLink, afterwareLink.concat(httpLink) ]); @@ -51,11 +38,11 @@ const buildClient = (settings: MiddlewareConfig) => { credentials: 'include', defaultOptions: { query: { - errorPolicy: "all", - fetchPolicy: "no-cache", + errorPolicy: 'all', + fetchPolicy: 'no-cache' }, mutate: { - errorPolicy: "all", + errorPolicy: 'all' } } }); diff --git a/packages/sdk-api-client/src/setup/logBuilder.ts b/packages/sdk-api-client/src/setup/logBuilder.ts index 73eefd3c..12daa1f3 100644 --- a/packages/sdk-api-client/src/setup/logBuilder.ts +++ b/packages/sdk-api-client/src/setup/logBuilder.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { Logger } from 'winston'; +import consola from 'consola'; interface LooseObject { label?: string, @@ -17,22 +17,15 @@ function getGqlString(doc: any) { } export default ({ label, message, locations, path, operation }: LooseObject) : void=> { - const logger : Logger = (process as any).winstonLog; - const log : LooseObject = { - label, - message: message, - path: path - }; + const log : LooseObject = { label, message: message, path: path }; if (locations) { log.location = locations?.map(item => `line: ${item.line} | column: ${item.column}`).join(' '); } - if (process.env.NODE_LOG_LEVEL === 'TRACE') { - log.query = getGqlString(operation.query); - log.variables = operation.variables; - } + log.query = getGqlString(operation.query); + log.variables = operation.variables; - logger.error(log); + consola.error(log); }; diff --git a/packages/sdk/src/connector.ts b/packages/sdk/src/connector.ts index 7508f1b9..657dd528 100644 --- a/packages/sdk/src/connector.ts +++ b/packages/sdk/src/connector.ts @@ -15,28 +15,28 @@ type Methods = typeof methods; * Initialize the Odoo connector. */ export const odooConnector = (options: Options): Methods => { - let mutation = null - let query = null - + let mutation = null; + let query = null; + mutation = async (metadata: MutationMetadataParams, params?: ApiParams): Promise => { return await client.post('mutation', [metadata, params]); - } + }; query = async (metadata: QueryMetadataParams, params?: ApiParams): Promise =>{ return await client.post('query', [metadata, params]); - } + }; - if(options.ofetch) { + if (options.ofetch) { mutation = async (metadata: MutationMetadataParams, params?: ApiParams): Promise => { - return await options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache' }) - } - + return await options.ofetch('/api/odoo/mutation', { method: 'POST', body: [metadata, params], cache: 'no-cache' }); + }; + query = async (metadata: QueryMetadataParams, params?: ApiParams): Promise =>{ - return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache' }) - } + return await options.ofetch('/api/odoo/query', { method: 'POST', body: [metadata, params], cache: 'no-cache' }); + }; } - client.defaults.baseURL = options.apiUrl + client.defaults.baseURL = options.apiUrl; return { query, mutation }; }; diff --git a/playground-nuxt/app/graphql/types.ts b/playground-nuxt/app/graphql/types.ts index 7d9589cf..cda5cd0f 100644 --- a/playground-nuxt/app/graphql/types.ts +++ b/playground-nuxt/app/graphql/types.ts @@ -1,11 +1,16 @@ -import { Partner, ProductVariant } from "~/graphql"; +import { _AsyncData } from 'nuxt/dist/app/composables/asyncData'; +import { H3Error } from 'h3'; +import { Partner, ProductVariant } from '~/graphql'; -export type ProductVariantQueryResponse = { +export type SalesPersonResponse = _AsyncData< + { productVariant: ProductVariant -} + }, + H3Error +>; -export type LoginMutationResponse = { +export type LoginMutationResponse = { login: { partner: Partner } -} \ No newline at end of file +} diff --git a/playground-nuxt/app/pages/index.vue b/playground-nuxt/app/pages/index.vue index 98ec939d..38b99776 100644 --- a/playground-nuxt/app/pages/index.vue +++ b/playground-nuxt/app/pages/index.vue @@ -1,23 +1,19 @@ diff --git a/playground-nuxt/app/plugins/2.getImage.client.ts b/playground-nuxt/app/plugins/2.getImage.ts similarity index 100% rename from playground-nuxt/app/plugins/2.getImage.client.ts rename to playground-nuxt/app/plugins/2.getImage.ts diff --git a/playground-nuxt/app/plugins/3.sdk.ts b/playground-nuxt/app/plugins/3.sdk.ts index df2b9410..6606cb47 100644 --- a/playground-nuxt/app/plugins/3.sdk.ts +++ b/playground-nuxt/app/plugins/3.sdk.ts @@ -1,13 +1,13 @@ import { initSDK, buildModule } from '@vue-storefront/sdk'; -import { OdooModule, OdooModuleType } from '../../../packages/sdk/src'; +import { OdooModule, OdooModuleType } from '../../../packages/sdk/src'; export default defineNuxtPlugin(async (nuxtApp) => { const config = useRuntimeConfig(); - + const sdkConfig = { odoo: buildModule(OdooModule, { apiUrl: `${config.public.middlewareUrl}api/odoo/`, - ofetch: $fetch + ofetch: useFetch }) }; diff --git a/playground-nuxt/app/server/queries/GetCategories.ts b/playground-nuxt/app/server/queries/GetCategories.ts new file mode 100644 index 00000000..9feb0a3d --- /dev/null +++ b/playground-nuxt/app/server/queries/GetCategories.ts @@ -0,0 +1,41 @@ +import { partnerFragment } from './fragments'; +import { gql } from '@apollo/client/core'; + +export default gql` +query( + $search: String + $filter: CategoryFilterInput + $currentPage: Int + $pageSize: Int + $sort: CategorySortInput +) { + categories( + search: $search + filter: $filter + currentPage: $currentPage + pageSize: $pageSize + sort: $sort + ) { + categories { + id + name + slug + childs { + id + name + slug + childs { + id + name + slug + } + } + parent { + id + name + slug + } + } + } +} +`; diff --git a/playground-nuxt/app/server/queries/GetProductTemplateList.ts b/playground-nuxt/app/server/queries/GetProductTemplateList.ts new file mode 100644 index 00000000..d325b1dc --- /dev/null +++ b/playground-nuxt/app/server/queries/GetProductTemplateList.ts @@ -0,0 +1,37 @@ +import { gql } from '@apollo/client/core'; + +export default gql` +query( + $filter: ProductFilterInput + $currentPage: Int + $pageSize: Int = 0 + $search: String + $sort: ProductSortInput +) { + products( + filter: $filter + currentPage: $currentPage + pageSize: $pageSize + search: $search + sort: $sort + ) { + totalCount + attributeValues { + id + name + displayType + name + htmlColor + search + attribute{ + id + name + } + + } + products { + id + } + } +} +`; diff --git a/playground-nuxt/app/server/queries/index.ts b/playground-nuxt/app/server/queries/index.ts index 883858d2..1cdb8460 100644 --- a/playground-nuxt/app/server/queries/index.ts +++ b/playground-nuxt/app/server/queries/index.ts @@ -1,15 +1,21 @@ import { DocumentNode } from '@apollo/client'; import ProductVariantQuery from './ProductVariantQuery'; import LoadUserQuery from './LoadUserQuery'; +import GetCategories from './GetCategories'; +import GetProductTemplateList from './GetProductTemplateList'; enum QueryName { ProductVariantQuery = 'ProductVariantQuery', - LoadUserQuery = 'LoadUserQuery' + LoadUserQuery = 'LoadUserQuery', + GetCategories = 'GetCategories', + GetProductTemplateList = 'GetProductTemplateList' } const Queries : Record = { ProductVariantQuery, - LoadUserQuery + LoadUserQuery, + GetCategories, + GetProductTemplateList }; export {