@graphcommerce/magento-graphql 9.0.4-canary.9 → 9.1.0-canary.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/mesh/magentoOrderItemResolvers.ts +51 -0
- package/mesh/magentoOrdersResolvers.ts +61 -0
- package/package.json +5 -5
- package/plugins/magentoOrderItemMesh.ts +28 -0
- package/plugins/magentoOrders.ts +28 -0
- package/schema-246/Customer-orders.graphqls +40 -0
- package/schema-247/CartItem-product.graphqls +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.1.0-canary.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2493](https://github.com/graphcommerce-org/graphcommerce/pull/2493) [`db56933`](https://github.com/graphcommerce-org/graphcommerce/commit/db569336dddd3e955ff0b5b00cafa25079f1adee) - Implemented order sorting for account overview and account list and implement custom resolver for Magento 2.4.5 (which is slow but works). ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
## 9.0.4-canary.14
|
|
10
|
+
|
|
11
|
+
## 9.0.4-canary.13
|
|
12
|
+
|
|
13
|
+
## 9.0.4-canary.12
|
|
14
|
+
|
|
15
|
+
## 9.0.4-canary.11
|
|
16
|
+
|
|
17
|
+
## 9.0.4-canary.10
|
|
18
|
+
|
|
3
19
|
## 9.0.4-canary.9
|
|
4
20
|
|
|
5
21
|
## 9.0.4-canary.8
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { fragments } from '@graphcommerce/graphql'
|
|
2
|
+
import {
|
|
3
|
+
selectionSetTemplate,
|
|
4
|
+
type Maybe,
|
|
5
|
+
type MeshContext,
|
|
6
|
+
type OrderItemInterfaceResolvers,
|
|
7
|
+
type ResolverFn,
|
|
8
|
+
type Resolvers,
|
|
9
|
+
type ResolversParentTypes,
|
|
10
|
+
type ResolversTypes,
|
|
11
|
+
} from '@graphcommerce/graphql-mesh'
|
|
12
|
+
|
|
13
|
+
type OrderItemTypes = NonNullable<Awaited<ReturnType<OrderItemInterfaceResolvers['__resolveType']>>>
|
|
14
|
+
const orderItemTypes = fragments.possibleTypes.OrderItemInterface as OrderItemTypes[]
|
|
15
|
+
|
|
16
|
+
export const resolvers: Resolvers = {}
|
|
17
|
+
|
|
18
|
+
type ProductResolver = ResolverFn<
|
|
19
|
+
Maybe<ResolversTypes['ProductInterface']>,
|
|
20
|
+
ResolversParentTypes['OrderItemInterface'],
|
|
21
|
+
MeshContext,
|
|
22
|
+
Record<string, never>
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
const productResolver: ProductResolver = async (root, args, context, info) => {
|
|
26
|
+
const { product_url_key, product } = root
|
|
27
|
+
if (product || !product_url_key) return product || null
|
|
28
|
+
|
|
29
|
+
const foundProduct = await context.m2.Query.products<string, ReturnType<ProductResolver>>({
|
|
30
|
+
key: product_url_key,
|
|
31
|
+
argsFromKeys: (keys) => ({ filter: { url_key: { in: keys } } }),
|
|
32
|
+
selectionSet: (node) => selectionSetTemplate`{ items { uid url_key ${node} } }`,
|
|
33
|
+
context,
|
|
34
|
+
info,
|
|
35
|
+
valuesFromResults: (results, keys) => {
|
|
36
|
+
const items = (results?.items ?? []).filter((i) => !!i)
|
|
37
|
+
return keys.map((key) => items.find((i) => i?.url_key === key) as ReturnType<ProductResolver>)
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return foundProduct
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
orderItemTypes.forEach((type) => {
|
|
45
|
+
if (!resolvers[type]) resolvers[type] = {}
|
|
46
|
+
|
|
47
|
+
resolvers[type].product = {
|
|
48
|
+
selectionSet: '{ product_url_key }',
|
|
49
|
+
resolve: productResolver,
|
|
50
|
+
}
|
|
51
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { execute, selectionSetTemplate, type Resolvers } from '@graphcommerce/graphql-mesh'
|
|
2
|
+
import { filterNonNullableKeys } from '@graphcommerce/next-ui'
|
|
3
|
+
|
|
4
|
+
export const resolvers: Resolvers = {
|
|
5
|
+
Customer: {
|
|
6
|
+
orders: async (root, args, context, info) => {
|
|
7
|
+
const { currentPage, pageSize, filter, scope, sort } = args
|
|
8
|
+
|
|
9
|
+
let items =
|
|
10
|
+
(
|
|
11
|
+
await context.m2.Query.customer({
|
|
12
|
+
info,
|
|
13
|
+
context,
|
|
14
|
+
selectionSet: (node) =>
|
|
15
|
+
selectionSetTemplate`{ orders(pageSize: 100) { number ${node} } }`,
|
|
16
|
+
})
|
|
17
|
+
)?.orders?.items ?? []
|
|
18
|
+
|
|
19
|
+
if (filter) {
|
|
20
|
+
items = items.filter((order) => {
|
|
21
|
+
if (!order?.number) return false
|
|
22
|
+
|
|
23
|
+
if (filter.number) {
|
|
24
|
+
if (filter.number.eq) return order?.number === filter.number.eq
|
|
25
|
+
if (filter.number.in) return filter.number.in.includes(order?.number ?? '')
|
|
26
|
+
if (filter.number.match) return order?.number?.match(filter.number.match)
|
|
27
|
+
}
|
|
28
|
+
return true
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
if (sort) {
|
|
32
|
+
items.sort((a, b) => {
|
|
33
|
+
if (sort.sort_field === 'NUMBER') {
|
|
34
|
+
return sort.sort_direction === 'DESC'
|
|
35
|
+
? (b?.number?.localeCompare(a?.number ?? '') ?? 0)
|
|
36
|
+
: (a?.number?.localeCompare(b?.number ?? '') ?? 0)
|
|
37
|
+
}
|
|
38
|
+
if (sort.sort_field === 'CREATED_AT') {
|
|
39
|
+
return sort.sort_direction === 'DESC'
|
|
40
|
+
? (b?.order_date?.localeCompare(a?.order_date ?? '') ?? 0)
|
|
41
|
+
: (a?.order_date?.localeCompare(b?.order_date ?? '') ?? 0)
|
|
42
|
+
}
|
|
43
|
+
return 0
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const totalCount = items.length
|
|
48
|
+
items = items.slice((currentPage - 1) * pageSize, currentPage * pageSize)
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
items,
|
|
52
|
+
page_info: {
|
|
53
|
+
total_pages: Math.ceil(totalCount / pageSize),
|
|
54
|
+
current_page: currentPage,
|
|
55
|
+
page_size: pageSize,
|
|
56
|
+
},
|
|
57
|
+
total_count: totalCount,
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-graphql",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0
|
|
5
|
+
"version": "9.1.0-canary.15",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "index.ts",
|
|
8
8
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^9.0
|
|
17
|
-
"@graphcommerce/graphql": "^9.0
|
|
18
|
-
"@graphcommerce/prettier-config-pwa": "^9.0
|
|
19
|
-
"@graphcommerce/typescript-config-pwa": "^9.0
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.1.0-canary.15",
|
|
17
|
+
"@graphcommerce/graphql": "^9.1.0-canary.15",
|
|
18
|
+
"@graphcommerce/prettier-config-pwa": "^9.1.0-canary.15",
|
|
19
|
+
"@graphcommerce/typescript-config-pwa": "^9.1.0-canary.15",
|
|
20
20
|
"graphql": "^16.0.0",
|
|
21
21
|
"next": "*",
|
|
22
22
|
"react": "^18.2.0",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { meshConfig as meshConfigBase } from '@graphcommerce/graphql-mesh/meshConfig'
|
|
2
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
|
|
4
|
+
export const config: PluginConfig = {
|
|
5
|
+
module: '@graphcommerce/graphql-mesh/meshConfig',
|
|
6
|
+
type: 'function',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const meshConfig: FunctionPlugin<typeof meshConfigBase> = (
|
|
10
|
+
prev,
|
|
11
|
+
baseConfig,
|
|
12
|
+
graphCommerceConfig,
|
|
13
|
+
) => {
|
|
14
|
+
if (graphCommerceConfig.magentoVersion >= 247) {
|
|
15
|
+
return prev(baseConfig, graphCommerceConfig)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return prev(
|
|
19
|
+
{
|
|
20
|
+
...baseConfig,
|
|
21
|
+
additionalResolvers: [
|
|
22
|
+
...(baseConfig.additionalResolvers ?? []),
|
|
23
|
+
'@graphcommerce/magento-graphql/mesh/magentoOrderItemResolvers.ts',
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
graphCommerceConfig,
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { meshConfig as meshConfigBase } from '@graphcommerce/graphql-mesh/meshConfig'
|
|
2
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
|
|
4
|
+
export const config: PluginConfig = {
|
|
5
|
+
module: '@graphcommerce/graphql-mesh/meshConfig',
|
|
6
|
+
type: 'function',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const meshConfig: FunctionPlugin<typeof meshConfigBase> = (
|
|
10
|
+
prev,
|
|
11
|
+
baseConfig,
|
|
12
|
+
graphCommerceConfig,
|
|
13
|
+
) => {
|
|
14
|
+
if (graphCommerceConfig.magentoVersion >= 246) {
|
|
15
|
+
return prev(baseConfig, graphCommerceConfig)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return prev(
|
|
19
|
+
{
|
|
20
|
+
...baseConfig,
|
|
21
|
+
additionalResolvers: [
|
|
22
|
+
...(baseConfig.additionalResolvers ?? []),
|
|
23
|
+
'@graphcommerce/magento-graphql/mesh/magentoOrdersResolvers.ts',
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
graphCommerceConfig,
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
enum ScopeTypeEnum {
|
|
2
|
+
GLOBAL
|
|
3
|
+
WEBSITE
|
|
4
|
+
STORE
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
input CustomerOrderSortInput {
|
|
8
|
+
sort_direction: SortEnum!
|
|
9
|
+
sort_field: CustomerOrderSortableField!
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
enum CustomerOrderSortableField {
|
|
13
|
+
NUMBER
|
|
14
|
+
CREATED_AT
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
extend type Customer {
|
|
18
|
+
orders(
|
|
19
|
+
"""
|
|
20
|
+
Defines the filter to use for searching customer orders.
|
|
21
|
+
"""
|
|
22
|
+
filter: CustomerOrdersFilterInput
|
|
23
|
+
"""
|
|
24
|
+
Specifies which page of results to return. The default value is 1.
|
|
25
|
+
"""
|
|
26
|
+
currentPage: Int = 1
|
|
27
|
+
"""
|
|
28
|
+
Specifies the maximum number of results to return at once. The default value is 20.
|
|
29
|
+
"""
|
|
30
|
+
pageSize: Int = 20
|
|
31
|
+
"""
|
|
32
|
+
Specifies which field to sort on, and whether to return the results in ascending or descending order.
|
|
33
|
+
"""
|
|
34
|
+
sort: CustomerOrderSortInput
|
|
35
|
+
"""
|
|
36
|
+
Specifies the scope to search for customer orders. The Store request header identifies the customer's store view code. The default value of STORE limits the search to the value specified in the header. Specify WEBSITE to expand the search to include all customer orders assigned to the website that is defined in the header, or specify GLOBAL to include all customer orders across all websites and stores.
|
|
37
|
+
"""
|
|
38
|
+
scope: ScopeTypeEnum
|
|
39
|
+
): CustomerOrders
|
|
40
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
extend interface OrderItemInterface {
|
|
2
|
+
product: ProductInterface
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
extend type OrderItem {
|
|
6
|
+
product: ProductInterface
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
extend type BundleOrderItem {
|
|
10
|
+
product: ProductInterface
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
extend type DownloadableOrderItem {
|
|
14
|
+
product: ProductInterface
|
|
15
|
+
}
|