diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b3939..7fb3c68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Use translatableV2 +- Use translateV2 in search term ## [0.3.0] - 2019-09-20 ### Added diff --git a/graphql/types/Brand.graphql b/graphql/types/Brand.graphql index 65db8e9..4da168d 100644 --- a/graphql/types/Brand.graphql +++ b/graphql/types/Brand.graphql @@ -8,11 +8,11 @@ type Brand { """ Text link""" slug: String """ Name of brand """ - name: String @translatable + name: String @translatableV2 """ Title used by html tag""" - titleTag: String @translatable + titleTag: String @translatableV2 """ Description used by html tag""" - metaTagDescription: String @translatable + metaTagDescription: String @translatableV2 """ Brand is active """ active: Boolean } diff --git a/graphql/types/Category.graphql b/graphql/types/Category.graphql index d1c5d46..b7e4d81 100644 --- a/graphql/types/Category.graphql +++ b/graphql/types/Category.graphql @@ -8,13 +8,13 @@ type Category { """ Category ID """ id: Int """ Category name """ - name: String @translatable + name: String @translatableV2 """ Title used by html tag""" - titleTag: String @translatable + titleTag: String @translatableV2 """ Description used by html tag""" hasChildren: Boolean """ Has children categories """ - metaTagDescription: String @translatable + metaTagDescription: String @translatableV2 """ Categories children """ children: [Category] } diff --git a/graphql/types/Facets.graphql b/graphql/types/Facets.graphql index b2dce78..cd2617a 100644 --- a/graphql/types/Facets.graphql +++ b/graphql/types/Facets.graphql @@ -10,7 +10,7 @@ type Facets { type DepartmentFacet { id: ID! quantity: Int! - name: String @translatable + name: String @translatableV2 link: String! linkEncoded: String! map: String @@ -31,7 +31,7 @@ type BrandFacet { type PriceRangesFacet { quantity: Int! - name: String @translatable + name: String @translatableV2 link: String! linkEncoded: String! map: String @@ -43,7 +43,7 @@ type PriceRangesFacet { type CategoriesTreeFacet { id: ID! quantity: Int! - name: String @translatable + name: String @translatableV2 link: String! linkEncoded: String! """ @@ -58,7 +58,7 @@ type CategoriesTreeFacet { type FilterFacet { quantity: Int! - name: String @translatable + name: String @translatableV2 link: String! linkEncoded: String! map: String diff --git a/graphql/types/Product.graphql b/graphql/types/Product.graphql index 52fdb5b..f092a73 100644 --- a/graphql/types/Product.graphql +++ b/graphql/types/Product.graphql @@ -2,7 +2,7 @@ type Product { """ Brand of the product """ - brand: String @translatable + brand: String @translatableV2 """ Id of the brand of the product """ @@ -31,7 +31,7 @@ type Product { """ Product description """ - description: String @translatable + description: String @translatableV2 """ SKU objects of the product """ @@ -51,7 +51,7 @@ type Product { """ Product name """ - productName: String @translatable + productName: String @translatableV2 """ Array of product properties """ @@ -67,11 +67,11 @@ type Product { """ Title used by html tag """ - titleTag: String @translatable + titleTag: String @translatableV2 """ Description used by html tag """ - metaTagDescription: String @translatable + metaTagDescription: String @translatableV2 """ Related Products """ @@ -135,8 +135,8 @@ type Recommendation { type SKU { itemId: ID - name: String @translatable - nameComplete: String @translatable + name: String @translatableV2 + nameComplete: String @translatableV2 complementName: String ean: String referenceId: [Reference] @@ -151,13 +151,13 @@ type SKU { } type skuSpecification { - fieldName: String @translatable - fieldValues: [String] @translatable + fieldName: String @translatableV2 + fieldValues: [String] @translatableV2 } type productSpecification { - fieldName: String @translatable - fieldValues: [String] @translatable + fieldName: String @translatableV2 + fieldValues: [String] @translatableV2 } input ProductUniqueIdentifier { @@ -273,13 +273,13 @@ type Video { } type SpecificationGroup { - name: String @translatable + name: String @translatableV2 specifications: [SpecificationGroupProperty] } type SpecificationGroupProperty { - name: String @translatable - values: [String] @translatable + name: String @translatableV2 + values: [String] @translatableV2 } type Property { diff --git a/graphql/types/ProductSearch.graphql b/graphql/types/ProductSearch.graphql index 55a688f..5453f42 100644 --- a/graphql/types/ProductSearch.graphql +++ b/graphql/types/ProductSearch.graphql @@ -7,7 +7,7 @@ type ProductSearch { } type SearchBreadcrumb { - name: String @translatable + name: String @translatableV2 href: String } diff --git a/graphql/types/Suggestions.graphql b/graphql/types/Suggestions.graphql index 9b53b97..05ce5b6 100644 --- a/graphql/types/Suggestions.graphql +++ b/graphql/types/Suggestions.graphql @@ -6,7 +6,7 @@ type Suggestions { type Items { thumb: String - name: String @translatable + name: String @translatableV2 href: String criteria: String slug: String diff --git a/manifest.json b/manifest.json index 921c37e..6a964aa 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "vendor": "vtex", "name": "search-graphql", - "version": "0.3.0", + "version": "0.4.0-beta.1", "title": "GraphQL API for the VTEX store APIs", "description": "GraphQL schema and resolvers for the VTEX API for the catalog and orders.", "credentialType": "absolute", diff --git a/node/package.json b/node/package.json index 4caa975..ca6b57a 100644 --- a/node/package.json +++ b/node/package.json @@ -32,7 +32,7 @@ "@types/node": "10.x", "@types/qs": "^6.5.1", "@types/ramda": "^0.26.21", - "@vtex/api": "^3.41.0", + "@vtex/api": "^3.54.1", "@vtex/test-tools": "^1.2.0", "@vtex/tsconfig": "^0.2.0", "eslint": "^5.15.3", diff --git a/node/resolvers/catalog/assemblyOption.test.ts b/node/resolvers/catalog/assemblyOption.test.ts index bac55ac..3c4010a 100644 --- a/node/resolvers/catalog/assemblyOption.test.ts +++ b/node/resolvers/catalog/assemblyOption.test.ts @@ -83,4 +83,4 @@ test('should return a BOOLEAN type', async () => { expect(thingB.maxLength).toBe(undefined) expect(thingB.domain).not.toBeDefined() expect(thingB.defaultValue).toBe(false) -}) \ No newline at end of file +}) diff --git a/node/resolvers/catalog/autocomplete.ts b/node/resolvers/catalog/autocomplete.ts index b24b8c3..dbcc67f 100644 --- a/node/resolvers/catalog/autocomplete.ts +++ b/node/resolvers/catalog/autocomplete.ts @@ -1,7 +1,5 @@ import { path, split } from 'ramda' -import { toIOMessage, toProductIOMessage } from '../../utils/ioMessage' - /** * It will extract the slug from the HREF in the item * passed as parameter. @@ -22,17 +20,6 @@ const extractSlug = (item: CatalogAutocompleteUnit) => { export const resolvers = { Items: { - name: ( - { name, items }: CatalogAutocompleteUnit, - _: any, - { clients: { segment } }: Context - ) => { - const id = path([0, 'productId'], items) - return id != null - ? toProductIOMessage('name')(segment, name, id) - : toIOMessage(segment, name, name) - }, - slug: (root: CatalogAutocompleteUnit) => extractSlug(root), productId: ({ items }: CatalogAutocompleteUnit) => diff --git a/node/resolvers/catalog/brand.ts b/node/resolvers/catalog/brand.ts index 6265a60..a466000 100644 --- a/node/resolvers/catalog/brand.ts +++ b/node/resolvers/catalog/brand.ts @@ -1,26 +1,11 @@ import { prop } from 'ramda' -import { toBrandIOMessage } from './../../utils/ioMessage' import { catalogSlugify } from '../../utils/slug' export const resolvers = { Brand: { - name: ({ name, id }: Brand, _: any, { clients: { segment } }: Context) => - toBrandIOMessage('name')(segment, name, id), - titleTag: ( - { title, id }: Brand, - _: any, - { clients: { segment } }: Context - ) => title && toBrandIOMessage('titleTag')(segment, title, id), - - metaTagDescription: ( - { metaTagDescription, id }: Brand, - _: any, - { clients: { segment } }: Context - ) => - metaTagDescription && - toBrandIOMessage('metaTagDescription')(segment, metaTagDescription, id), + titleTag: prop('title'), active: prop('isActive'), diff --git a/node/resolvers/catalog/category.ts b/node/resolvers/catalog/category.ts index c303f0d..6b4b42e 100644 --- a/node/resolvers/catalog/category.ts +++ b/node/resolvers/catalog/category.ts @@ -1,6 +1,5 @@ import { compose, last, prop, split } from 'ramda' -import { toCategoryIOMessage } from '../../utils/ioMessage' import { getCategoryInfo } from './utils' const lastSegment = compose( @@ -35,33 +34,9 @@ export const resolvers = { return pathToCategoryHref(path) }, - name: async ( - { id, name }: SafeCategory, - _: any, - { clients: { segment } }: Context - ) => { - return toCategoryIOMessage('name')(segment, name, id) - }, - - metaTagDescription: async ( - { id, MetaTagDescription }: SafeCategory, - _: any, - { clients: { segment } }: Context - ) => { - return toCategoryIOMessage('metaTagDescription')( - segment, - MetaTagDescription, - id - ) - }, + metaTagDescription: prop('MetaTagDescription'), - titleTag: async ( - { id, Title }: SafeCategory, - _: any, - { clients: { segment } }: Context - ) => { - return toCategoryIOMessage('titleTag')(segment, Title, id) - }, + titleTag: prop('Title'), slug: async ({ url }: SafeCategory, _: any) => { return url ? lastSegment(url) : null diff --git a/node/resolvers/catalog/facets.ts b/node/resolvers/catalog/facets.ts index 2e90259..2a94f5b 100644 --- a/node/resolvers/catalog/facets.ts +++ b/node/resolvers/catalog/facets.ts @@ -1,6 +1,5 @@ import { prop, toPairs } from 'ramda' -import { toCategoryIOMessage, toFacetIOMessage } from '../../utils/ioMessage' import { pathToCategoryHref } from './category' import { zipQueryAndMap } from './utils' @@ -65,27 +64,14 @@ export const resolvers = { FilterFacet: { ...baseFacetResolvers, - name: async ( - { Map, Name }: CatalogFacet, - _: any, - { clients: { segment } }: Context - ) => { - const [, id] = Map.split('_') - return toFacetIOMessage(segment, Name, id) - }, + name: prop('Name'), }, DepartmentFacet: { ...baseFacetResolvers, id: prop('Id'), - name: async ( - { Id, Name }: CatalogFacet & { Id?: number }, - _: any, - { clients: { segment } }: Context - ) => { - return Id != null ? toCategoryIOMessage('name')(segment, Name, Id) : Name - }, + name: prop('Name'), }, BrandFacet: { ...baseFacetResolvers, @@ -109,11 +95,7 @@ export const resolvers = { return pathToCategoryHref(linkPath) }, - name: ( - { Id, Name }: CatalogFacetCategory, - _: any, - { clients: { segment } }: Context - ) => toCategoryIOMessage('name')(segment, Name, Id), + name: prop('Name'), }, Facets: { departments: ({ diff --git a/node/resolvers/catalog/index.ts b/node/resolvers/catalog/index.ts index 5234823..e548282 100644 --- a/node/resolvers/catalog/index.ts +++ b/node/resolvers/catalog/index.ts @@ -1,29 +1,26 @@ import { Functions } from '@gocommerce/utils' import { NotFoundError, UserInputError } from '@vtex/api' import { all } from 'bluebird' -import { head, test, isEmpty, isNil, path } from 'ramda' +import { head, isEmpty, isNil, path, test } from 'ramda' -import { toSearchTerm } from '../../utils/ioMessage' +import { resolvers as assemblyOptionResolvers } from './assemblyOption' import { resolvers as autocompleteResolvers } from './autocomplete' import { resolvers as brandResolvers } from './brand' import { resolvers as categoryResolvers } from './category' import { resolvers as discountResolvers } from './discount' import { resolvers as facetsResolvers } from './facets' import { resolvers as itemMetadataResolvers } from './itemMetadata' -import { resolvers as itemMetadataUnitResolvers } from './itemMetadataUnit' import { resolvers as itemMetadataPriceTableItemResolvers } from './itemMetadataPriceTableItem' +import { resolvers as itemMetadataUnitResolvers } from './itemMetadataUnit' +import { emptyTitleTag, getSearchMetaData } from './modules/metadata' import { resolvers as offerResolvers } from './offer' import { resolvers as productResolvers } from './product' import { resolvers as productSearchResolvers } from './productSearch' import { resolvers as recommendationResolvers } from './recommendation' import { resolvers as breadcrumbResolvers } from './searchBreadcrumb' import { resolvers as skuResolvers } from './sku' -import { resolvers as assemblyOptionResolvers } from './assemblyOption' - import { CatalogCrossSellingTypes } from './utils' -import { getSearchMetaData, emptyTitleTag } from './modules/metadata' - interface ProductIndentifier { field: 'id' | 'slug' | 'ean' | 'reference' | 'sku' value: string @@ -72,7 +69,11 @@ const translateToStoreDefaultLanguage = async ( segment.getSegment(), ]) return from && from !== to - ? messagesGraphQL.translate(toSearchTerm(term, from, to) as any).then(head) + ? messagesGraphQL.translateV2({ + messages: [{content: term}], + from, + to, + }).then(head) : term } diff --git a/node/resolvers/catalog/product.ts b/node/resolvers/catalog/product.ts index 8437bc9..0113b9a 100644 --- a/node/resolvers/catalog/product.ts +++ b/node/resolvers/catalog/product.ts @@ -1,25 +1,8 @@ -import { - compose, - last, - map, - omit, - propOr, - reject, - reverse, - split, - toPairs, - length, -} from 'ramda' - import { Functions } from '@gocommerce/utils' +import { compose, last, length, map, omit, prop, propOr, reject, reverse, split, toPairs } from 'ramda' -import { - toBrandIOMessage, - toProductIOMessage, - toSpecificationIOMessage, -} from './../../utils/ioMessage' -import { buildCategoryMap, hashMD5 } from './utils' import { getBenefits } from '../benefits' +import { buildCategoryMap } from './utils' type MaybeRecord = false | Record const objToNameValue = ( @@ -99,35 +82,6 @@ export const resolvers = { categoryTree: productCategoriesToCategoryTree, - productName: ( - { productName, productId }: CatalogProduct, - _: any, - { clients: { segment } }: Context - ) => toProductIOMessage('name')(segment, productName, productId), - - description: ( - { description, productId }: CatalogProduct, - _: any, - { clients: { segment } }: Context - ) => toProductIOMessage('description')(segment, description, productId), - - brand: ( - { brand, brandId }: CatalogProduct, - _: any, - { clients: { segment } }: Context - ) => toBrandIOMessage('name')(segment, brand, brandId), - - metaTagDescription: ( - { metaTagDescription, productId }: CatalogProduct, - _: any, - { clients: { segment } }: Context - ) => - toProductIOMessage('metaTagDescription')( - segment, - metaTagDescription, - productId - ), - cacheId: ({ linkText }: CatalogProduct) => linkText, clusterHighlights: ({ clusterHighlights = {} }) => @@ -162,16 +116,10 @@ export const resolvers = { recommendations: (product: CatalogProduct) => product, - titleTag: ( - { productTitle, productId }: CatalogProduct, - _: any, - { clients: { segment } }: Context - ) => toProductIOMessage('titleTag')(segment, productTitle, productId), + titleTag: prop('productTitle'), specificationGroups: ( product: CatalogProduct, - _: any, - { clients: { segment } }: Context ) => { const allSpecificationsGroups = propOr<[], CatalogProduct, string[]>( [], @@ -180,25 +128,11 @@ export const resolvers = { ).concat(['allSpecifications']) const specificationGroups = allSpecificationsGroups.map( (groupName: string) => ({ - name: toSpecificationIOMessage('groupName')( - segment, - groupName, - hashMD5(groupName) - ), + name: groupName, specifications: ((product as any)[groupName] || []).map( (name: string) => ({ - name: toSpecificationIOMessage('specificationName')( - segment, - name, - hashMD5(name) - ), - values: ((product as any)[name] || []).map((value: string) => - toSpecificationIOMessage('specificationValue')( - segment, - value, - hashMD5(value) - ) - ), + name, + values: ((product as any)[name] || []), }) ), }) diff --git a/node/resolvers/catalog/searchBreadcrumb.ts b/node/resolvers/catalog/searchBreadcrumb.ts index 1c34654..efbdfbd 100644 --- a/node/resolvers/catalog/searchBreadcrumb.ts +++ b/node/resolvers/catalog/searchBreadcrumb.ts @@ -1,8 +1,8 @@ -import { equals, toLower, includes } from 'ramda' -import { toCategoryIOMessage, toClusterIOMessage } from '../../utils/ioMessage' -import { findCategoryInTree, getBrandFromSlug } from './utils' import { Functions } from '@gocommerce/utils' +import { equals, includes, toLower } from 'ramda' + import { getSpecificationFilterName } from './modules/metadata' +import { findCategoryInTree, getBrandFromSlug } from './utils' interface BreadcrumbParams { queryUnit: string @@ -81,7 +81,6 @@ export const resolvers = { SearchBreadcrumb: { name: async (obj: BreadcrumbParams, _: any, ctx: Context) => { const { - clients: { segment }, vtex: { account }, } = ctx const { queryUnit, mapUnit, index, queryArray, products } = obj @@ -90,17 +89,13 @@ export const resolvers = { if (isProductClusterMap(mapUnit)) { const clusterName = findClusterNameFromId(products, queryUnit) if (clusterName) { - return toClusterIOMessage(segment, clusterName, queryUnit) + return clusterName } } if (isCategoryMap(mapUnit)) { const categoryData = await getCategoryInfo(obj, isVtex, ctx) if (categoryData) { - return toCategoryIOMessage('name')( - segment, - categoryData.name, - categoryData.id - ) + return categoryData.name } } if (isSellerMap(mapUnit)) { diff --git a/node/resolvers/catalog/sku.ts b/node/resolvers/catalog/sku.ts index 239294e..6a9a27f 100644 --- a/node/resolvers/catalog/sku.ts +++ b/node/resolvers/catalog/sku.ts @@ -1,7 +1,5 @@ import { find, head, map, replace, slice } from 'ramda' -import { toSKUIOMessage } from './../../utils/ioMessage' - export const resolvers = { SKU: { attachments: ({ attachments = [] }: CatalogItem) => @@ -54,17 +52,5 @@ export const resolvers = { }), Videos ), - - nameComplete: ( - { nameComplete, itemId }: CatalogItem, - _: any, - { clients: { segment } }: Context - ) => toSKUIOMessage('nameComplete')(segment, nameComplete, itemId), - - name: ( - { name, itemId }: CatalogItem, - _: any, - { clients: { segment } }: Context - ) => toSKUIOMessage('name')(segment, name, itemId), }, } diff --git a/node/utils/ioMessage.ts b/node/utils/ioMessage.ts deleted file mode 100644 index c50c794..0000000 --- a/node/utils/ioMessage.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { Segment } from '@vtex/api' -import { prop } from 'ramda' -import { Slugify } from './slug' - -const localeFromDefaultSalesChannel = (segment: Segment) => - segment.getSegmentByToken(null).then(prop('cultureInfo')) - -export const toIOMessage = async ( - segment: Segment, - content: string, - id: string -) => ({ - content, - from: await localeFromDefaultSalesChannel(segment), - id, -}) - -export const toProductIOMessage = (field: string) => ( - segment: Segment, - content: string, - id: string -) => toIOMessage(segment, content, `Product-id.${id}::${field}`) - -export const toCategoryIOMessage = (field: string) => ( - segment: Segment, - content: string, - id: number | string -) => toIOMessage(segment, content, `Category-id.${id}::${field}`) - -export const toFacetIOMessage = ( - segment: Segment, - content: string, - id: string -) => toIOMessage(segment, content, `SpecificationFilter-id.${id}::${content}`) - -export const toClusterIOMessage = ( - segment: Segment, - content: string, - id: string -) => toIOMessage(segment, content, `ProductCluster-id.${id}::${content}`) - -export const toSKUIOMessage = (field: string) => ( - segment: Segment, - content: string, - id: string -) => toIOMessage(segment, content, `SKU-id.${id}::${field}`) - -export const toBrandIOMessage = (field: string) => ( - segment: Segment, - content: string, - id: number | string -) => toIOMessage(segment, content, `Brand-id.${id}::${field}`) - -export const toSpecificationIOMessage = (field: string) => ( - segment: Segment, - content: string, - id: string -) => toIOMessage(segment, content, `Specification-id.${id}::${field}`) - -export const toSearchTerm = ( - term: string, - from: string, - to: string, - description: string = '' -) => ({ - messages: [ - { - provider: 'Search', - messages: [ - { - id: Slugify(term), - content: term, - description, - }, - ], - }, - ], - from, - to, -}) diff --git a/node/yarn.lock b/node/yarn.lock index 9a044a5..db33090 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1413,13 +1413,14 @@ lodash.unescape "4.0.1" semver "5.5.0" -"@vtex/api@^3.41.0": - version "3.46.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-3.46.0.tgz#f43a58ce15e08dfa366daf44a4c2ec4928527236" - integrity sha512-Dqlu/LE6mn1oUIb744bjj+RgNbb+xMSB0C6H6RcUvVGOQPJgY4OfqNY11jae6qjInWXIVVyBkRKFwnFpUNqfxA== +"@vtex/api@^3.54.1": + version "3.54.1" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-3.54.1.tgz#9d14d7693993ef542a6a49396396995fdfc75442" + integrity sha512-3xlkQ239XIhSZPQ+ok1X9w5iPy606+YZ+xBITKDhMtcpP0x2EXrTDY5SnREfEIniLQDEuzHKzEKNPbF3zhSQww== dependencies: "@types/koa" "^2.0.48" "@types/koa-compose" "^3.2.3" + "@wry/equality" "^0.1.9" apollo-datasource "^0.3.1" apollo-server-core "^2.4.8" apollo-server-errors "^2.2.1" @@ -1502,7 +1503,7 @@ "@types/node" ">=6" tslib "^1.9.3" -"@wry/equality@^0.1.2": +"@wry/equality@^0.1.2", "@wry/equality@^0.1.9": version "0.1.9" resolved "https://registry.yarnpkg.com/@wry/equality/-/equality-0.1.9.tgz#b13e18b7a8053c6858aa6c85b54911fb31e3a909" integrity sha512-mB6ceGjpMGz1ZTza8HYnrPGos2mC6So4NhS1PtZ8s4Qt0K7fBiIGhpSxUbQmhwcSWE3no+bYxmI2OL6KuXYmoQ== @@ -5738,7 +5739,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -stats-lite@vtex/node-stats-lite#dist: +"stats-lite@github:vtex/node-stats-lite#dist": version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: