From 71a5baa54ea028de16bcd5027edb64598018b8b5 Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Tue, 5 Dec 2023 15:17:26 +0100 Subject: [PATCH 1/8] [GCOM-1307] add migration for edited DR schema --- .../dist/migrations/graphcommerce7to7_1.js | 35 +++++++++++++++ packages/hygraph-cli/dist/migrations/index.js | 1 + .../src/migrations/graphcommerce7to7_1.ts | 43 +++++++++++++++++++ packages/hygraph-cli/src/migrations/index.ts | 1 + 4 files changed, 80 insertions(+) create mode 100644 packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js create mode 100644 packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js b/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js new file mode 100644 index 0000000000..1691e5e22b --- /dev/null +++ b/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js @@ -0,0 +1,35 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.graphcommerce7to7_1 = void 0; +const management_sdk_1 = require("@hygraph/management-sdk"); +const migrationAction_1 = require("../migrationAction"); +const graphcommerce7to7_1 = async (schema) => { + if (!migrationAction_1.client) { + return 0; + } + // const schema.models.some((m) => m.fields.some((f) => f.apiId === 'row')) + const hasRow = schema.models + .find((m) => m.apiId === 'DynamicRow') + ?.fields.some((f) => f.apiId === 'row'); + if (hasRow) { + (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'delete', { + apiId: 'row', + parentApiId: 'DynamicRow', + }); + } + (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', { + displayName: 'Rows', + apiId: 'rows', + isList: true, + reverseField: { + modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], + apiId: 'dynamicRow', + displayName: 'DynamicRows', + visibility: management_sdk_1.VisibilityTypes.Hidden, + isList: true, + }, + parentApiId: 'DynamicRow', + }, 'DynamicRow', 'model'); + return migrationAction_1.client.run(true); +}; +exports.graphcommerce7to7_1 = graphcommerce7to7_1; diff --git a/packages/hygraph-cli/dist/migrations/index.js b/packages/hygraph-cli/dist/migrations/index.js index 359a8699ab..f70dc3bb19 100644 --- a/packages/hygraph-cli/dist/migrations/index.js +++ b/packages/hygraph-cli/dist/migrations/index.js @@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./graphcommerce5to6"), exports); __exportStar(require("./graphcommerce6to7"), exports); +__exportStar(require("./graphcommerce7to7_1"), exports); diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts new file mode 100644 index 0000000000..2ef8004462 --- /dev/null +++ b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts @@ -0,0 +1,43 @@ +import { VisibilityTypes } from '@hygraph/management-sdk' +import { migrationAction, client } from '../migrationAction' +import { Schema } from '../types' + +export const graphcommerce7to7_1 = async (schema: Schema) => { + if (!client) { + return 0 + } + // const schema.models.some((m) => m.fields.some((f) => f.apiId === 'row')) + const hasRow = schema.models + .find((m) => m.apiId === 'DynamicRow') + ?.fields.some((f) => f.apiId === 'row') + + if (hasRow) { + migrationAction(schema, 'simpleField', 'delete', { + apiId: 'row', + parentApiId: 'DynamicRow', + }) + } + + migrationAction( + schema, + 'unionField', + 'create', + { + displayName: 'Rows', + apiId: 'rows', + isList: true, + reverseField: { + modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], + apiId: 'dynamicRow', + displayName: 'DynamicRows', + visibility: VisibilityTypes.Hidden, + isList: true, + }, + parentApiId: 'DynamicRow', + }, + 'DynamicRow', + 'model', + ) + + return client.run(true) +} diff --git a/packages/hygraph-cli/src/migrations/index.ts b/packages/hygraph-cli/src/migrations/index.ts index 1054c496f0..2851f7a3ba 100644 --- a/packages/hygraph-cli/src/migrations/index.ts +++ b/packages/hygraph-cli/src/migrations/index.ts @@ -1,2 +1,3 @@ export * from './graphcommerce5to6' export * from './graphcommerce6to7' +export * from './graphcommerce7to7_1' From 40272b945c2a0a226ccbdaea42e1eb2a1a34c088 Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Tue, 5 Dec 2023 15:22:01 +0100 Subject: [PATCH 2/8] [GCOM-1307] enable multiple rows per DR --- .../graphql/DynamicRow.graphql | 2 +- .../hygraph-dynamic-rows/lib/hygraphDynamicRows.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql b/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql index 5c7cedbbf2..710864195c 100644 --- a/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql +++ b/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql @@ -6,7 +6,7 @@ fragment DynamicRow on DynamicRow @injectable { } } - row { + rows { __typename ... on Node { id diff --git a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts index 17dbd11caa..59e56f685e 100644 --- a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts +++ b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts @@ -123,19 +123,19 @@ export async function hygraphDynamicRows( const content = [...(pageResult.data.pages[0]?.content ?? [])] dynamicResult?.data.dynamicRows.forEach((dynamicRow) => { - const { placement, target, row } = dynamicRow - if (!row) return + const { placement, target, rows } = dynamicRow + if (!rows) return if (!target) { - if (placement === 'BEFORE') content.unshift(row) - else content.push(row) + if (placement === 'BEFORE') content.unshift(...rows) + else content.push(...rows) return } const targetIdx = content.findIndex((c) => c.id === target.id) - if (placement === 'BEFORE') content.splice(targetIdx, 0, row) - if (placement === 'AFTER') content.splice(targetIdx + 1, 0, row) - if (placement === 'REPLACE') content.splice(targetIdx, 1, row) + if (placement === 'BEFORE') content.splice(targetIdx, 0, ...rows) + if (placement === 'AFTER') content.splice(targetIdx + 1, 0, ...rows) + if (placement === 'REPLACE') content.splice(targetIdx, 1, ...rows) }) if (!content.length) return pageResult From 2ad71809bbfdf3972635870b801cc30d04209177 Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Tue, 5 Dec 2023 15:56:58 +0100 Subject: [PATCH 3/8] [GCOM-1307] cleanup --- packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts index 2ef8004462..0529bdd506 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts @@ -6,7 +6,7 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { if (!client) { return 0 } - // const schema.models.some((m) => m.fields.some((f) => f.apiId === 'row')) + const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row') From 70bda70d71fa418cc0680e7e5848095046f2da04 Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Wed, 6 Dec 2023 12:30:05 +0100 Subject: [PATCH 4/8] [GCOM-1307] deprecate row field --- .../migrations/graphcommerce7_unknown_to_8.js | 22 +++++++++++++++++ .../dist/migrations/graphcommerce7to7_1.js | 22 +++++++++++++++-- .../migrations/graphcommerce7_unknown_to_8.ts | 24 +++++++++++++++++++ .../src/migrations/graphcommerce7to7_1.ts | 23 +++++++++++++++++- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js create mode 100644 packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js b/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js new file mode 100644 index 0000000000..3ac6a2320e --- /dev/null +++ b/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.graphcommerce7_unknown_to_8 = void 0; +const migrationAction_1 = require("../migrationAction"); +const graphcommerce7_unknown_to_8 = async (schema) => { + if (!migrationAction_1.client) { + return 0; + } + // This migration is for GC 8.0 and is not yet exported as a usable migration. + // Removes the deprecated 'Row' field which was replaced by Rows in GC@7.1 + const hasRow = schema.models + .find((m) => m.apiId === 'DynamicRow') + ?.fields.some((f) => f.apiId === 'row'); + if (hasRow) { + (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'delete', { + apiId: 'row', + parentApiId: 'DynamicRow', + }); + } + return migrationAction_1.client.run(true); +}; +exports.graphcommerce7_unknown_to_8 = graphcommerce7_unknown_to_8; diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js b/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js index 1691e5e22b..3c326cc141 100644 --- a/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js +++ b/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js @@ -7,7 +7,10 @@ const graphcommerce7to7_1 = async (schema) => { if (!migrationAction_1.client) { return 0; } - // const schema.models.some((m) => m.fields.some((f) => f.apiId === 'row')) + /** + * Running this migration will cause a loss in entries for the 'row' field in the DynamicRow model. + * The field is replaced by Rows. Row will be deprecated so Graphcommerce 7.0 will still keep running. + **/ const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row'); @@ -16,6 +19,21 @@ const graphcommerce7to7_1 = async (schema) => { apiId: 'row', parentApiId: 'DynamicRow', }); + (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', { + apiId: 'row', + displayName: 'Row Deprecated', + parentApiId: 'DynamicRow', + description: 'This field is deprecated. Use Rows instead.', + visibility: management_sdk_1.VisibilityTypes.Hidden, + reverseField: { + modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], + apiId: 'dynamicRowDeprecated', + displayName: 'DynamicRows Deprecated', + description: 'This field is deprecated. Use Dynamic Rows instead.', + visibility: management_sdk_1.VisibilityTypes.Hidden, + isList: true, + }, + }); } (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', { displayName: 'Rows', @@ -24,7 +42,7 @@ const graphcommerce7to7_1 = async (schema) => { reverseField: { modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], apiId: 'dynamicRow', - displayName: 'DynamicRows', + displayName: 'Dynamic Rows', visibility: management_sdk_1.VisibilityTypes.Hidden, isList: true, }, diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts b/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts new file mode 100644 index 0000000000..600472fd0f --- /dev/null +++ b/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts @@ -0,0 +1,24 @@ +import { migrationAction, client } from '../migrationAction' +import { Schema } from '../types' + +export const graphcommerce7_unknown_to_8 = async (schema: Schema) => { + if (!client) { + return 0 + } + + // This migration is for GC 8.0 and is not yet exported as a usable migration. + + // Removes the deprecated 'Row' field which was replaced by Rows in GC@7.1 + const hasRow = schema.models + .find((m) => m.apiId === 'DynamicRow') + ?.fields.some((f) => f.apiId === 'row') + + if (hasRow) { + migrationAction(schema, 'simpleField', 'delete', { + apiId: 'row', + parentApiId: 'DynamicRow', + }) + } + + return client.run(true) +} diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts index 0529bdd506..9f5092c9dd 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts @@ -7,6 +7,11 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { return 0 } + /** + * Running this migration will cause a loss in entries for the 'row' field in the DynamicRow model. + * The field is replaced by Rows. Row will be deprecated so Graphcommerce 7.0 will still keep running. + **/ + const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row') @@ -16,6 +21,22 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { apiId: 'row', parentApiId: 'DynamicRow', }) + + migrationAction(schema, 'unionField', 'create', { + apiId: 'row', + displayName: 'Row Deprecated', + parentApiId: 'DynamicRow', + description: 'This field is deprecated. Use Rows instead.', + visibility: VisibilityTypes.Hidden, + reverseField: { + modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], + apiId: 'dynamicRowDeprecated', + displayName: 'DynamicRows Deprecated', + description: 'This field is deprecated. Use Dynamic Rows instead.', + visibility: VisibilityTypes.Hidden, + isList: true, + }, + }) } migrationAction( @@ -29,7 +50,7 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { reverseField: { modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], apiId: 'dynamicRow', - displayName: 'DynamicRows', + displayName: 'Dynamic Rows', visibility: VisibilityTypes.Hidden, isList: true, }, From f8296aeeb16d817df056b7f77cf39b5d1efd3c4a Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Wed, 6 Dec 2023 14:49:46 +0100 Subject: [PATCH 5/8] [GCOM-1307] prevent breaking changes --- .../migrations/graphcommerce7_unknown_to_8.js | 2 +- .../dist/migrations/graphcommerce7to7_1.js | 21 ++--------------- .../migrations/graphcommerce7_unknown_to_8.ts | 2 +- .../src/migrations/graphcommerce7to7_1.ts | 23 ++----------------- .../graphql/DynamicRow.graphql | 11 +++++++++ .../lib/hygraphDynamicRows.ts | 18 ++++++++------- 6 files changed, 27 insertions(+), 50 deletions(-) diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js b/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js index 3ac6a2320e..6bfcb964ee 100644 --- a/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js +++ b/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js @@ -7,7 +7,7 @@ const graphcommerce7_unknown_to_8 = async (schema) => { return 0; } // This migration is for GC 8.0 and is not yet exported as a usable migration. - // Removes the deprecated 'Row' field which was replaced by Rows in GC@7.1 + // Removes the deprecated 'Row' field which was deprecated in GC@7.1 const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row'); diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js b/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js index 3c326cc141..c8105f1b2e 100644 --- a/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js +++ b/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js @@ -7,32 +7,15 @@ const graphcommerce7to7_1 = async (schema) => { if (!migrationAction_1.client) { return 0; } - /** - * Running this migration will cause a loss in entries for the 'row' field in the DynamicRow model. - * The field is replaced by Rows. Row will be deprecated so Graphcommerce 7.0 will still keep running. - **/ const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row'); if (hasRow) { - (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'delete', { - apiId: 'row', - parentApiId: 'DynamicRow', - }); - (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', { + (0, migrationAction_1.migrationAction)(schema, 'unionField', 'update', { apiId: 'row', displayName: 'Row Deprecated', parentApiId: 'DynamicRow', description: 'This field is deprecated. Use Rows instead.', - visibility: management_sdk_1.VisibilityTypes.Hidden, - reverseField: { - modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], - apiId: 'dynamicRowDeprecated', - displayName: 'DynamicRows Deprecated', - description: 'This field is deprecated. Use Dynamic Rows instead.', - visibility: management_sdk_1.VisibilityTypes.Hidden, - isList: true, - }, }); } (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', { @@ -41,7 +24,7 @@ const graphcommerce7to7_1 = async (schema) => { isList: true, reverseField: { modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], - apiId: 'dynamicRow', + apiId: 'dynamicRows', displayName: 'Dynamic Rows', visibility: management_sdk_1.VisibilityTypes.Hidden, isList: true, diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts b/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts index 600472fd0f..b89cc495d2 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts @@ -8,7 +8,7 @@ export const graphcommerce7_unknown_to_8 = async (schema: Schema) => { // This migration is for GC 8.0 and is not yet exported as a usable migration. - // Removes the deprecated 'Row' field which was replaced by Rows in GC@7.1 + // Removes the deprecated 'Row' field which was deprecated in GC@7.1 const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row') diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts index 9f5092c9dd..e9ce127b4e 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts @@ -7,35 +7,16 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { return 0 } - /** - * Running this migration will cause a loss in entries for the 'row' field in the DynamicRow model. - * The field is replaced by Rows. Row will be deprecated so Graphcommerce 7.0 will still keep running. - **/ - const hasRow = schema.models .find((m) => m.apiId === 'DynamicRow') ?.fields.some((f) => f.apiId === 'row') if (hasRow) { - migrationAction(schema, 'simpleField', 'delete', { - apiId: 'row', - parentApiId: 'DynamicRow', - }) - - migrationAction(schema, 'unionField', 'create', { + migrationAction(schema, 'unionField', 'update', { apiId: 'row', displayName: 'Row Deprecated', parentApiId: 'DynamicRow', description: 'This field is deprecated. Use Rows instead.', - visibility: VisibilityTypes.Hidden, - reverseField: { - modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], - apiId: 'dynamicRowDeprecated', - displayName: 'DynamicRows Deprecated', - description: 'This field is deprecated. Use Dynamic Rows instead.', - visibility: VisibilityTypes.Hidden, - isList: true, - }, }) } @@ -49,7 +30,7 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { isList: true, reverseField: { modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], - apiId: 'dynamicRow', + apiId: 'dynamicRows', displayName: 'Dynamic Rows', visibility: VisibilityTypes.Hidden, isList: true, diff --git a/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql b/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql index 710864195c..75cce77337 100644 --- a/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql +++ b/packages/hygraph-dynamic-rows/graphql/DynamicRow.graphql @@ -6,6 +6,17 @@ fragment DynamicRow on DynamicRow @injectable { } } + row { + __typename + ... on Node { + id + } + + ...RowColumnOne + ...RowQuote + ...RowLinks + } + rows { __typename ... on Node { diff --git a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts index 59e56f685e..cf927594c1 100644 --- a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts +++ b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts @@ -120,22 +120,24 @@ export async function hygraphDynamicRows( const [pageResult, dynamicResult] = await Promise.all([pageQuery, dynamicRows]) // Create a copy of the content array. - const content = [...(pageResult.data.pages[0]?.content ?? [])] + const content = pageResult.data.pages[0]?.content ?? [] dynamicResult?.data.dynamicRows.forEach((dynamicRow) => { - const { placement, target, rows } = dynamicRow - if (!rows) return + const { placement, target, rows, row } = dynamicRow + if (!rows && !row) return + + const rowsToMerge = [...rows, row] if (!target) { - if (placement === 'BEFORE') content.unshift(...rows) - else content.push(...rows) + if (placement === 'BEFORE') content.unshift(...rowsToMerge) + else content.push(...rowsToMerge) return } const targetIdx = content.findIndex((c) => c.id === target.id) - if (placement === 'BEFORE') content.splice(targetIdx, 0, ...rows) - if (placement === 'AFTER') content.splice(targetIdx + 1, 0, ...rows) - if (placement === 'REPLACE') content.splice(targetIdx, 1, ...rows) + if (placement === 'BEFORE') content.splice(targetIdx, 0, ...rowsToMerge) + if (placement === 'AFTER') content.splice(targetIdx + 1, 0, ...rowsToMerge) + if (placement === 'REPLACE') content.splice(targetIdx, 1, ...rowsToMerge) }) if (!content.length) return pageResult From 8c543e65c3b39510c3204944f8902a40dcc64328 Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Wed, 6 Dec 2023 15:00:04 +0100 Subject: [PATCH 6/8] [GCOM-1307] optimize Dyn Row --- packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts index cf927594c1..5993a71dd2 100644 --- a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts +++ b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts @@ -126,7 +126,7 @@ export async function hygraphDynamicRows( const { placement, target, rows, row } = dynamicRow if (!rows && !row) return - const rowsToMerge = [...rows, row] + const rowsToMerge = rows ?? [row] if (!target) { if (placement === 'BEFORE') content.unshift(...rowsToMerge) From a5e47df9f84c591f148717b6f2a5a3f4e23aee84 Mon Sep 17 00:00:00 2001 From: Joshua Bolk Date: Wed, 6 Dec 2023 15:20:02 +0100 Subject: [PATCH 7/8] [GCOM-1307] optimize Dyn Row --- packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts index 5993a71dd2..1d52a95cc1 100644 --- a/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts +++ b/packages/hygraph-dynamic-rows/lib/hygraphDynamicRows.ts @@ -126,7 +126,7 @@ export async function hygraphDynamicRows( const { placement, target, rows, row } = dynamicRow if (!rows && !row) return - const rowsToMerge = rows ?? [row] + const rowsToMerge = rows.length > 0 ? rows : [row] if (!target) { if (placement === 'BEFORE') content.unshift(...rowsToMerge) From 50d90a2849c1556c696c7fe4e65454e1de0b730e Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Mon, 15 Jan 2024 13:57:11 +0100 Subject: [PATCH 8/8] Renamed upgrades to reflect the new major version 8 --- ...commerce7to7_1.js => graphcommerce7to8.js} | 0 ...7_unknown_to_8.js => graphcommerce8to9.js} | 0 packages/hygraph-cli/dist/migrations/index.js | 2 +- ...commerce7to7_1.ts => graphcommerce7to8.ts} | 0 ...7_unknown_to_8.ts => graphcommerce8to9.ts} | 0 packages/hygraph-cli/src/migrations/index.ts | 2 +- .../next-config/dist/withGraphCommerce.js | 24 +++++++++---------- 7 files changed, 13 insertions(+), 15 deletions(-) rename packages/hygraph-cli/dist/migrations/{graphcommerce7to7_1.js => graphcommerce7to8.js} (100%) rename packages/hygraph-cli/dist/migrations/{graphcommerce7_unknown_to_8.js => graphcommerce8to9.js} (100%) rename packages/hygraph-cli/src/migrations/{graphcommerce7to7_1.ts => graphcommerce7to8.ts} (100%) rename packages/hygraph-cli/src/migrations/{graphcommerce7_unknown_to_8.ts => graphcommerce8to9.ts} (100%) diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js b/packages/hygraph-cli/dist/migrations/graphcommerce7to8.js similarity index 100% rename from packages/hygraph-cli/dist/migrations/graphcommerce7to7_1.js rename to packages/hygraph-cli/dist/migrations/graphcommerce7to8.js diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js b/packages/hygraph-cli/dist/migrations/graphcommerce8to9.js similarity index 100% rename from packages/hygraph-cli/dist/migrations/graphcommerce7_unknown_to_8.js rename to packages/hygraph-cli/dist/migrations/graphcommerce8to9.js diff --git a/packages/hygraph-cli/dist/migrations/index.js b/packages/hygraph-cli/dist/migrations/index.js index f70dc3bb19..08f89ad918 100644 --- a/packages/hygraph-cli/dist/migrations/index.js +++ b/packages/hygraph-cli/dist/migrations/index.js @@ -16,4 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./graphcommerce5to6"), exports); __exportStar(require("./graphcommerce6to7"), exports); -__exportStar(require("./graphcommerce7to7_1"), exports); +__exportStar(require("./graphcommerce7to8"), exports); diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts b/packages/hygraph-cli/src/migrations/graphcommerce7to8.ts similarity index 100% rename from packages/hygraph-cli/src/migrations/graphcommerce7to7_1.ts rename to packages/hygraph-cli/src/migrations/graphcommerce7to8.ts diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts b/packages/hygraph-cli/src/migrations/graphcommerce8to9.ts similarity index 100% rename from packages/hygraph-cli/src/migrations/graphcommerce7_unknown_to_8.ts rename to packages/hygraph-cli/src/migrations/graphcommerce8to9.ts diff --git a/packages/hygraph-cli/src/migrations/index.ts b/packages/hygraph-cli/src/migrations/index.ts index 2851f7a3ba..3c07b40660 100644 --- a/packages/hygraph-cli/src/migrations/index.ts +++ b/packages/hygraph-cli/src/migrations/index.ts @@ -1,3 +1,3 @@ export * from './graphcommerce5to6' export * from './graphcommerce6to7' -export * from './graphcommerce7to7_1' +export * from './graphcommerce7to8' diff --git a/packagesDev/next-config/dist/withGraphCommerce.js b/packagesDev/next-config/dist/withGraphCommerce.js index 8430a5d8bb..3f14595b7f 100644 --- a/packagesDev/next-config/dist/withGraphCommerce.js +++ b/packagesDev/next-config/dist/withGraphCommerce.js @@ -65,19 +65,17 @@ function withGraphCommerce(nextConfig, cwd) { }, redirects: async () => { const redirects = (await nextConfig.redirects?.()) ?? []; - if (!graphcommerceConfig.legacyProductRoute) { - const destination = `${graphcommerceConfig.productRoute ?? '/p/'}:url*`; - redirects.push(...[ - { source: '/product/bundle/:url*', destination, permanent: true }, - { source: '/product/configurable/:url*', destination, permanent: true }, - { source: '/product/downloadable/:url*', destination, permanent: true }, - { source: '/product/grouped/:url*', destination, permanent: true }, - { source: '/product/virtual/:url*', destination, permanent: true }, - { source: '/customer/account', destination: '/account', permanent: true }, - ]); - if (destination !== '/product/:url*') - redirects.push({ source: '/product/:url*', destination, permanent: true }); - } + const destination = `${graphcommerceConfig.productRoute ?? '/p/'}:url*`; + redirects.push(...[ + { source: '/product/bundle/:url*', destination, permanent: true }, + { source: '/product/configurable/:url*', destination, permanent: true }, + { source: '/product/downloadable/:url*', destination, permanent: true }, + { source: '/product/grouped/:url*', destination, permanent: true }, + { source: '/product/virtual/:url*', destination, permanent: true }, + { source: '/customer/account', destination: '/account', permanent: true }, + ]); + if (destination !== '/product/:url*') + redirects.push({ source: '/product/:url*', destination, permanent: true }); return redirects; }, rewrites: async () => {