Skip to content

Commit

Permalink
feat: add "productSpecificationGroups" resolver to order form Item (#191
Browse files Browse the repository at this point in the history
)

#### What problem is this solving?

Add resolver "productSpecificationGroups" to `Item`

In Fashion segment it's common to have different product colours as
different (similar) products instead of SKUs, due to the limited number
of SKUs we can have on the platform. It's impossible to get product
specifications (such as colour) in the current `orderForm`
implementation without having to make an extra API call for each item,
impacting user experience. For mobile apps this is unfeasible.

#### How should this be manually tested?

GraphQL IDE on the following
[Workspace](https://productspecificationresolver--oficinareserva.myvtex.com/admin/graphql-ide)

**Query**

```gql
query ProductSpecificationGroups($orderFormId: ID, $refreshOutdatedData: Boolean) {
  orderForm(orderFormId: $orderFormId, refreshOutdatedData: $refreshOutdatedData)   {
    items {
      id
      productSpecificationGroups {
        name
        originalName
        specifications {
          name
          originalName
          values
        }
      }
    }
  }
}
```

#### Checklist/Reminders

- [x] Updated `README.md`.
- [x] Updated `CHANGELOG.md`.
- [ ] Linked this PR to a Jira story (if applicable).
- [ ] Updated/created tests (important for bug fixes).
- [ ] Deleted the workspace after merging this PR (if applicable).

#### Type of changes

<!--- Add a ✔️ where applicable -->
✔️ | Type of Change
---|---
_ | Bug fix <!-- a non-breaking change which fixes an issue -->
✔️ | New feature <!-- a non-breaking change which adds functionality -->
_ | Breaking change <!-- fix or feature that would cause existing
functionality to change -->
_ | Technical improvements <!-- chores, refactors and overall reduction
of technical debt -->

#### Notes

<!-- Put any relevant information that doesn't fit in the other sections
here. -->
  • Loading branch information
pedrobernardina authored Feb 27, 2024
1 parent 2287d6e commit 7409e69
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `productSpecificationGroups` resolver to `Item` type

## [0.66.3] - 2023-08-04

### Fixed
Expand Down
13 changes: 13 additions & 0 deletions graphql/types/Item.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Item {
price: Float
productCategories: ProductCategoriesObject
productCategoryIds: String
productSpecificationGroups: [ProductSpecificationGroups]!
"""
Id of the product. Can be null if included inside bundle items.
"""
Expand Down Expand Up @@ -105,6 +106,18 @@ type SKUSpecification {
fieldValues: [String]! @translatableV2
}

type ProductSpecification {
name: String @translatableV2
originalName: String @translatableV2
values: [String]! @translatableV2
}

type ProductSpecificationGroups {
name: String @translatableV2
originalName: String @translatableV2
specifications: [ProductSpecification]!
}

type AssemblyOptionType {
assemblyId: String!
id: ID
Expand Down
18 changes: 18 additions & 0 deletions node/clients/searchGraphQL/productQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export interface ProductResponse {
values: string[]
}>
}>
specificationGroups: Array<{
name: string
originalName: string
specifications: Array<{
name: string
originalName: string
values: string[]
}>
}>
}

export interface ProductsByIdentifierResponse {
Expand All @@ -32,6 +41,15 @@ query Product($values: [ID!]!) {
values
}
}
specificationGroups {
name
originalName
specifications {
name
originalName
values
}
}
}
}
`
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/node": "^12.0.0",
"@types/ramda": "types/npm-ramda#dist",
"@types/set-cookie-parser": "^2.4.2",
"@vtex/api": "6.45.15",
"@vtex/api": "6.45.20",
"@vtex/test-tools": "^3.1.0",
"@vtex/tsconfig": "^0.2.0",
"typescript": "3.9.7",
Expand Down
14 changes: 14 additions & 0 deletions node/resolvers/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ export const root = {

return getVariations(item.id, product?.items ?? [])
},
productSpecificationGroups: async (
item: OrderFormItem,
_: unknown,
ctx: Context
) => {
const {
vtex: { logger },
clients: { searchGraphQL },
} = ctx

const product = await getProductInfo(item, searchGraphQL, logger)

return product?.specificationGroups ?? []
},
},
}

Expand Down
14 changes: 14 additions & 0 deletions node/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ declare global {
offeringTypeId: any | null
}
productCategories: Record<string, string>
productSpecificationGroups: ProductSpecificationGroup[]
productRefId: string
seller: string
sellerChain: string[]
Expand All @@ -164,6 +165,18 @@ declare global {
fieldValues: string[]
}

interface ProductSpecification {
name: string
originalName: string
values: string[]
}

interface ProductSpecificationGroup {
name: string
originalName: string
specifications: ProductSpecification[]
}

interface CompositionItem {
id: string
minQuantity: number
Expand Down Expand Up @@ -486,6 +499,7 @@ declare global {
productId: string
productCategories: Record<string, string>
productCategoryIds: string
productSpecificationGroups: ProductSpecificationGroup[]
productRefId: string
quantity: number
sellingPrice: number
Expand Down
75 changes: 48 additions & 27 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1604,10 +1604,10 @@
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d"
integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==

"@vtex/[email protected].15":
version "6.45.15"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.15.tgz#aa987d22f7df16ce2861130deda6ffd63156817b"
integrity sha512-Rg1VGDzJ4hHUNp1vSidMdGGPojr1PikMTptlZsJ3oNZVdEo4cPx2l8ZcAEwHWORL7QjPjXaEgmeA5ZOSf+boCQ==
"@vtex/[email protected].20":
version "6.45.20"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.20.tgz#c1090249a424fd700499de3fed0d80d99ff53332"
integrity sha512-O7RJWWr4PfvixNpc0GgQh85iKcv9j1IKkpApwJQSW/WzxoTgSrcjYHOVUmJ1GWWBmRV/qvB2VaV6Ow1QL3UOCQ==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand All @@ -1627,7 +1627,7 @@
fs-extra "^7.0.0"
graphql "^14.5.8"
graphql-tools "^4.0.6"
graphql-upload "^8.1.0"
graphql-upload "^13.0.0"
jaeger-client "^3.18.0"
js-base64 "^2.5.1"
koa "^2.11.0"
Expand All @@ -1638,7 +1638,7 @@
mime-types "^2.1.12"
opentracing "^0.14.4"
p-limit "^2.2.0"
prom-client "^12.0.0"
prom-client "^14.2.0"
qs "^6.5.1"
querystring "^0.2.0"
ramda "^0.26.0"
Expand Down Expand Up @@ -3018,10 +3018,10 @@ fresh@~0.5.2:
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7"
integrity sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=

fs-capacitor@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/fs-capacitor/-/fs-capacitor-2.0.4.tgz#5a22e72d40ae5078b4fe64fe4d08c0d3fc88ad3c"
integrity sha512-8S4f4WsCryNw2mJJchi46YgB6CR5Ze+4L1h8ewl9tEpL4SJ3ZO+c/bS4BWhB8bK+O3TMqhuZarTitd0S0eh2pA==
fs-capacitor@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/fs-capacitor/-/fs-capacitor-6.2.0.tgz#fa79ac6576629163cb84561995602d8999afb7f5"
integrity sha512-nKcE1UduoSKX27NSZlg879LdQc94OtbOsEmKMN2MBNudXREvijRKx2GEBsTMTfws+BrbkJoEuynbGSVRSpauvw==

fs-constants@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -3169,15 +3169,15 @@ graphql-tools@^4.0.0, graphql-tools@^4.0.6:
iterall "^1.1.3"
uuid "^3.1.0"

graphql-upload@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/graphql-upload/-/graphql-upload-8.1.0.tgz#6d0ab662db5677a68bfb1f2c870ab2544c14939a"
integrity sha512-U2OiDI5VxYmzRKw0Z2dmfk0zkqMRaecH9Smh1U277gVgVe9Qn+18xqf4skwr4YJszGIh7iQDZ57+5ygOK9sM/Q==
graphql-upload@^13.0.0:
version "13.0.0"
resolved "https://registry.yarnpkg.com/graphql-upload/-/graphql-upload-13.0.0.tgz#1a255b64d3cbf3c9f9171fa62a8fb0b9b59bb1d9"
integrity sha512-YKhx8m/uOtKu4Y1UzBFJhbBGJTlk7k4CydlUUiNrtxnwZv0WigbRHP+DVhRNKt7u7DXOtcKZeYJlGtnMXvreXA==
dependencies:
busboy "^0.3.1"
fs-capacitor "^2.0.4"
http-errors "^1.7.3"
object-path "^0.11.4"
fs-capacitor "^6.2.0"
http-errors "^1.8.1"
object-path "^0.11.8"

graphql@*:
version "14.5.7"
Expand Down Expand Up @@ -3324,7 +3324,7 @@ http-assert@^1.3.0:
deep-equal "~1.0.1"
http-errors "~1.7.2"

[email protected], http-errors@^1.3.1, http-errors@^1.6.3, http-errors@^1.7.3, http-errors@~1.7.2:
[email protected], http-errors@^1.3.1, http-errors@^1.6.3, http-errors@~1.7.2:
version "1.7.3"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06"
integrity sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==
Expand All @@ -3335,6 +3335,17 @@ [email protected], http-errors@^1.3.1, http-errors@^1.6.3, http-errors@^1.7.3, h
statuses ">= 1.5.0 < 2"
toidentifier "1.0.0"

http-errors@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.8.1.tgz#7c3f28577cbc8a207388455dbd62295ed07bd68c"
integrity sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==
dependencies:
depd "~1.1.2"
inherits "2.0.4"
setprototypeof "1.2.0"
statuses ">= 1.5.0 < 2"
toidentifier "1.0.1"

http-signature@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1"
Expand Down Expand Up @@ -4753,10 +4764,10 @@ object-keys@^1.0.12:
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.12.tgz#09c53855377575310cca62f55bb334abff7b3ed2"
integrity sha512-FTMyFUm2wBcGHnH2eXmz7tC6IwlqQZ6mVZ+6dm6vZ4IQIHjs6FdNsQBuKGPuUUUY6NfJw2PshC08Tn6LzLDOag==

object-path@^0.11.4:
version "0.11.7"
resolved "https://registry.yarnpkg.com/object-path/-/object-path-0.11.7.tgz#5f211161f34bb395e4b13a5f565b79d933b6f65d"
integrity sha512-T4evaK9VfGGQskXBDILcn6F90ZD+WO3OwRFFQ2rmZdUH4vQeDBpiolTpVlPY2yj5xSepyILTjDyM6UvbbdHMZw==
object-path@^0.11.8:
version "0.11.8"
resolved "https://registry.yarnpkg.com/object-path/-/object-path-0.11.8.tgz#ed002c02bbdd0070b78a27455e8ae01fc14d4742"
integrity sha512-YJjNZrlXJFM42wTBn6zgOJVar9KFJvzx6sTWDte8sWZF//cnjl0BxHNpfZx+ZffXX63A9q0b1zsFiBX4g4X5KA==

object-visit@^1.0.0:
version "1.0.1"
Expand Down Expand Up @@ -5035,10 +5046,10 @@ process@^0.10.0:
resolved "https://registry.yarnpkg.com/process/-/process-0.10.1.tgz#842457cc51cfed72dc775afeeafb8c6034372725"
integrity sha1-hCRXzFHP7XLcd1r+6vuMYDQ3JyU=

prom-client@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-12.0.0.tgz#9689379b19bd3f6ab88a9866124db9da3d76c6ed"
integrity sha512-JbzzHnw0VDwCvoqf8y1WDtq4wSBAbthMB1pcVI/0lzdqHGJI3KBJDXle70XK+c7Iv93Gihqo0a5LlOn+g8+DrQ==
prom-client@^14.2.0:
version "14.2.0"
resolved "https://registry.yarnpkg.com/prom-client/-/prom-client-14.2.0.tgz#ca94504e64156f6506574c25fb1c34df7812cf11"
integrity sha512-sF308EhTenb/pDRPakm+WgiN+VdM/T1RaHj1x+MvAuT8UiQP8JmOEbxVqtkbfR4LrvOg5n7ic01kRBDGXjYikA==
dependencies:
tdigest "^0.1.1"

Expand Down Expand Up @@ -5557,6 +5568,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683"
integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==

shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
Expand Down Expand Up @@ -5714,7 +5730,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:
Expand Down Expand Up @@ -5978,6 +5994,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==

tokenbucket@^0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/tokenbucket/-/tokenbucket-0.3.2.tgz#8172b2b58e3083acc8d914426fed15162a3a8e90"
Expand Down

0 comments on commit 7409e69

Please sign in to comment.