diff --git a/.changeset/twelve-socks-tap.md b/.changeset/twelve-socks-tap.md new file mode 100644 index 0000000000..b709fb2e6b --- /dev/null +++ b/.changeset/twelve-socks-tap.md @@ -0,0 +1,6 @@ +--- +"@graphcommerce/next-config": patch +"@graphcommerce/hygraph-cli": patch +--- + +Solve issue where a Hygraph DynamicRow conditions were missing fields in the OrCondition diff --git a/docs/framework/config.md b/docs/framework/config.md index edd166a7ab..30a8cb36c0 100644 --- a/docs/framework/config.md +++ b/docs/framework/config.md @@ -205,6 +205,10 @@ The Google Tagmanager ID to be used on the site. This value is required even if you are configuring different values for each locale. +#### hygraphManagementApi: string + +Hygraph Management API. **Only used for migrations.** + #### hygraphProjectId: string Hygraph Project ID. **Only used for migrations.** diff --git a/docs/hygraph/cli.md b/docs/hygraph/cli.md index e2b5efdc1f..bc8b0177aa 100644 --- a/docs/hygraph/cli.md +++ b/docs/hygraph/cli.md @@ -48,16 +48,20 @@ The following steps are needed to utilize this tool: - Update public content views - Delete public content views - Can see schema view - 5. Add this new token to your env file: `GC_HYGRAPH_WRITE_ACCESS_TOKEN=""` + 5. Add this new token to your env file: + `GC_HYGRAPH_WRITE_ACCESS_TOKEN="{YOUR_WRITE_ACCESS_TOKEN}"` 2. Add the Content API key to your env file like this: 1. Open your Hygraph project. Go to: Project settings -> API Access 2. Copy the Content API URL and add to your env file: - `GC_HYGRAPH_WRITE_ACCESS_ENDPOINT=""` + `GC_HYGRAPH_WRITE_ACCESS_ENDPOINT="{YOUR_WRITE_ACCESS_ENDPOINT}"` 3. Add your hygraphProjectId to your env file like this: 1. Copy the project ID from the URL when logged in `https://app.hygraph.com/PROJECT_ID_IS_HERE/master` - 2. Add the project ID to your env file: `GC_HYGRAPH_PROJECT_ID=””` -4. Run `yarn graphcommerce hygraph-migrate` -5. Select the migration you want to run and press enter. -6. The migrations should now be applied, check your Hygraph Schema if changes + 2. Add the project ID to your env file: + `GC_HYGRAPH_PROJECT_ID=”{YOUR_PROJECT_ID}”` +4. Add your hygraphManagementApi to your env file like this: + `GC_HYGRAPH_MANAGEMENT_API="{YOUR_MANAGEMENT_API}"` +5. Run `yarn graphcommerce hygraph-migrate` +6. Select the migration you want to run and press enter. +7. The migrations should now be applied, check your Hygraph Schema if changes are made. diff --git a/packages/hygraph-cli/Config.graphqls b/packages/hygraph-cli/Config.graphqls index aeab871984..0a39758598 100644 --- a/packages/hygraph-cli/Config.graphqls +++ b/packages/hygraph-cli/Config.graphqls @@ -45,4 +45,9 @@ extend input GraphCommerceConfig { Hygraph Project ID. **Only used for migrations.** """ hygraphProjectId: String + + """ + Hygraph Management API. **Only used for migrations.** + """ + hygraphManagementApi: String } diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce6to7.js b/packages/hygraph-cli/dist/migrations/graphcommerce6to7.js index 8306ec416a..1d03064073 100644 --- a/packages/hygraph-cli/dist/migrations/graphcommerce6to7.js +++ b/packages/hygraph-cli/dist/migrations/graphcommerce6to7.js @@ -196,6 +196,13 @@ const graphcommerce6to7 = async (schema) => { enumerationApiId: 'RowColumnOneVariants', parentApiId: 'RowColumnOne', }, 'RowColumnOne', 'model'); + (0, migrationAction_1.migrationAction)(schema, 'componentUnionField', 'create', { + displayName: 'Conditions', + apiId: 'conditions', + parentApiId: 'ConditionOr', + componentApiIds: ['ConditionText', 'ConditionNumber'], + isList: true, + }, 'ConditionOr', 'component'); return migrationAction_1.client.run(true); }; exports.graphcommerce6to7 = graphcommerce6to7; diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce7to8.js b/packages/hygraph-cli/dist/migrations/graphcommerce7to8.js index c8105f1b2e..ee78731e8b 100644 --- a/packages/hygraph-cli/dist/migrations/graphcommerce7to8.js +++ b/packages/hygraph-cli/dist/migrations/graphcommerce7to8.js @@ -1,36 +1,57 @@ -"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 hasRow = schema.models - .find((m) => m.apiId === 'DynamicRow') - ?.fields.some((f) => f.apiId === 'row'); - if (hasRow) { - (0, migrationAction_1.migrationAction)(schema, 'unionField', 'update', { - apiId: 'row', - displayName: 'Row Deprecated', - parentApiId: 'DynamicRow', - description: 'This field is deprecated. Use Rows instead.', - }); - } - (0, migrationAction_1.migrationAction)(schema, 'unionField', 'create', { - displayName: 'Rows', - apiId: 'rows', +'use strict' +Object.defineProperty(exports, '__esModule', { value: true }) +exports.graphcommerce7to8 = void 0 +const management_sdk_1 = require('@hygraph/management-sdk') +const migrationAction_1 = require('../migrationAction') +const graphcommerce7to8 = async (schema) => { + if (!migrationAction_1.client) { + return 0 + } + const hasRow = schema.models + .find((m) => m.apiId === 'DynamicRow') + ?.fields.some((f) => f.apiId === 'row') + if (hasRow) { + ;(0, migrationAction_1.migrationAction)(schema, 'unionField', 'update', { + apiId: 'row', + displayName: 'Row Deprecated', + parentApiId: 'DynamicRow', + description: 'This field is deprecated. Use Rows instead.', + }) + } + ;(0, migrationAction_1.migrationAction)( + schema, + 'unionField', + 'create', + { + displayName: 'Rows', + apiId: 'rows', + isList: true, + reverseField: { + modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], + apiId: 'dynamicRows', + displayName: 'Dynamic Rows', + visibility: management_sdk_1.VisibilityTypes.Hidden, isList: true, - reverseField: { - modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'], - apiId: 'dynamicRows', - displayName: 'Dynamic Rows', - visibility: management_sdk_1.VisibilityTypes.Hidden, - isList: true, - }, - parentApiId: 'DynamicRow', - }, 'DynamicRow', 'model'); - return migrationAction_1.client.run(true); -}; -exports.graphcommerce7to7_1 = graphcommerce7to7_1; + }, + parentApiId: 'DynamicRow', + }, + 'DynamicRow', + 'model', + ) + ;(0, migrationAction_1.migrationAction)( + schema, + 'componentUnionField', + 'create', + { + displayName: 'Conditions', + apiId: 'conditions', + parentApiId: 'ConditionOr', + componentApiIds: ['ConditionText', 'ConditionNumber'], + isList: true, + }, + 'ConditionOr', + 'component', + ) + return migrationAction_1.client.run(true) +} +exports.graphcommerce7to8 = graphcommerce7to8 diff --git a/packages/hygraph-cli/dist/migrations/graphcommerce8to9.js b/packages/hygraph-cli/dist/migrations/graphcommerce8to9.js index 6bfcb964ee..ce241566ce 100644 --- a/packages/hygraph-cli/dist/migrations/graphcommerce8to9.js +++ b/packages/hygraph-cli/dist/migrations/graphcommerce8to9.js @@ -1,8 +1,8 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.graphcommerce7_unknown_to_8 = void 0; +exports.graphcommerce8to9 = void 0; const migrationAction_1 = require("../migrationAction"); -const graphcommerce7_unknown_to_8 = async (schema) => { +const graphcommerce8to9 = async (schema) => { if (!migrationAction_1.client) { return 0; } @@ -19,4 +19,4 @@ const graphcommerce7_unknown_to_8 = async (schema) => { } return migrationAction_1.client.run(true); }; -exports.graphcommerce7_unknown_to_8 = graphcommerce7_unknown_to_8; +exports.graphcommerce8to9 = graphcommerce8to9; diff --git a/packages/hygraph-cli/dist/migrations/index.js b/packages/hygraph-cli/dist/migrations/index.js index 08f89ad918..13edf69bab 100644 --- a/packages/hygraph-cli/dist/migrations/index.js +++ b/packages/hygraph-cli/dist/migrations/index.js @@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./graphcommerce5to6"), exports); __exportStar(require("./graphcommerce6to7"), exports); __exportStar(require("./graphcommerce7to8"), exports); +__exportStar(require("./graphcommerce8to9"), exports); diff --git a/packages/hygraph-cli/dist/readSchema.js b/packages/hygraph-cli/dist/readSchema.js index 4a23e0a789..ff09a1fa6a 100644 --- a/packages/hygraph-cli/dist/readSchema.js +++ b/packages/hygraph-cli/dist/readSchema.js @@ -5,15 +5,18 @@ const client_1 = require("@apollo/client"); const fetch_1 = require("@whatwg-node/fetch"); const readSchema = async (config) => { if (!config.hygraphProjectId) { - throw new Error('Please provide GC_HYGRAPH_PROJECT_ID in your env file'); + throw new Error('Please provide GC_HYGRAPH_PROJECT_ID in your env file.'); } if (!config.hygraphWriteAccessToken) { - throw new Error('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file'); + throw new Error('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file.'); } const projectId = config.hygraphProjectId; + if (!config.hygraphManagementApi) { + throw new Error('Please provide GC_HYGRAPH_MANAGEMENT_API in your env file.'); + } const hygraphClient = new client_1.ApolloClient({ link: new client_1.HttpLink({ - uri: 'https://management.hygraph.com/graphql', + uri: config.hygraphManagementApi, fetch: fetch_1.fetch, headers: { Authorization: `Bearer ${config.hygraphWriteAccessToken}` }, }), diff --git a/packages/hygraph-cli/src/migrations/graphcommerce6to7.ts b/packages/hygraph-cli/src/migrations/graphcommerce6to7.ts index 8c9a5288d9..6189720265 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce6to7.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce6to7.ts @@ -303,5 +303,20 @@ export const graphcommerce6to7 = async (schema: Schema) => { 'model', ) + migrationAction( + schema, + 'componentUnionField', + 'create', + { + displayName: 'Conditions', + apiId: 'conditions', + parentApiId: 'ConditionOr', + componentApiIds: ['ConditionText', 'ConditionNumber'], + isList: true, + }, + 'ConditionOr', + 'component', + ) + return client.run(true) } diff --git a/packages/hygraph-cli/src/migrations/graphcommerce7to8.ts b/packages/hygraph-cli/src/migrations/graphcommerce7to8.ts index e9ce127b4e..cbd6cac193 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce7to8.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce7to8.ts @@ -2,7 +2,7 @@ import { VisibilityTypes } from '@hygraph/management-sdk' import { migrationAction, client } from '../migrationAction' import { Schema } from '../types' -export const graphcommerce7to7_1 = async (schema: Schema) => { +export const graphcommerce7to8 = async (schema: Schema) => { if (!client) { return 0 } @@ -41,5 +41,20 @@ export const graphcommerce7to7_1 = async (schema: Schema) => { 'model', ) + migrationAction( + schema, + 'componentUnionField', + 'create', + { + displayName: 'Conditions', + apiId: 'conditions', + parentApiId: 'ConditionOr', + componentApiIds: ['ConditionText', 'ConditionNumber'], + isList: true, + }, + 'ConditionOr', + 'component', + ) + return client.run(true) } diff --git a/packages/hygraph-cli/src/migrations/graphcommerce8to9.ts b/packages/hygraph-cli/src/migrations/graphcommerce8to9.ts index b89cc495d2..1664c62ec2 100644 --- a/packages/hygraph-cli/src/migrations/graphcommerce8to9.ts +++ b/packages/hygraph-cli/src/migrations/graphcommerce8to9.ts @@ -1,7 +1,7 @@ import { migrationAction, client } from '../migrationAction' import { Schema } from '../types' -export const graphcommerce7_unknown_to_8 = async (schema: Schema) => { +export const graphcommerce8to9 = async (schema: Schema) => { if (!client) { return 0 } diff --git a/packages/hygraph-cli/src/migrations/index.ts b/packages/hygraph-cli/src/migrations/index.ts index 3c07b40660..9d5e84152f 100644 --- a/packages/hygraph-cli/src/migrations/index.ts +++ b/packages/hygraph-cli/src/migrations/index.ts @@ -1,3 +1,4 @@ export * from './graphcommerce5to6' export * from './graphcommerce6to7' export * from './graphcommerce7to8' +export * from './graphcommerce8to9' diff --git a/packages/hygraph-cli/src/readSchema.ts b/packages/hygraph-cli/src/readSchema.ts index c7924e817e..f78ae8fb76 100644 --- a/packages/hygraph-cli/src/readSchema.ts +++ b/packages/hygraph-cli/src/readSchema.ts @@ -4,18 +4,22 @@ import { fetch } from '@whatwg-node/fetch' export const readSchema = async (config: GraphCommerceConfig) => { if (!config.hygraphProjectId) { - throw new Error('Please provide GC_HYGRAPH_PROJECT_ID in your env file') + throw new Error('Please provide GC_HYGRAPH_PROJECT_ID in your env file.') } if (!config.hygraphWriteAccessToken) { - throw new Error('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file') + throw new Error('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file.') } const projectId = config.hygraphProjectId + if (!config.hygraphManagementApi) { + throw new Error('Please provide GC_HYGRAPH_MANAGEMENT_API in your env file.') + } + const hygraphClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://management.hygraph.com/graphql', + uri: config.hygraphManagementApi, fetch, headers: { Authorization: `Bearer ${config.hygraphWriteAccessToken}` }, }), diff --git a/packagesDev/next-config/dist/generated/config.js b/packagesDev/next-config/dist/generated/config.js index bc4149a910..d125aaeb5c 100644 --- a/packagesDev/next-config/dist/generated/config.js +++ b/packagesDev/next-config/dist/generated/config.js @@ -76,6 +76,7 @@ function GraphCommerceConfigSchema() { googleRecaptchaKey: _zod.z.string().nullish(), googleTagmanagerId: _zod.z.string().nullish(), hygraphEndpoint: _zod.z.string().min(1), + hygraphManagementApi: _zod.z.string().nullish(), hygraphProjectId: _zod.z.string().nullish(), hygraphWriteAccessEndpoint: _zod.z.string().nullish(), hygraphWriteAccessToken: _zod.z.string().nullish(), diff --git a/packagesDev/next-config/src/generated/config.ts b/packagesDev/next-config/src/generated/config.ts index 181ec620b1..7930163645 100644 --- a/packagesDev/next-config/src/generated/config.ts +++ b/packagesDev/next-config/src/generated/config.ts @@ -211,6 +211,8 @@ export type GraphCommerceConfig = { * Project settings -> API Access -> High Performance Read-only Content API */ hygraphEndpoint: Scalars['String']['input']; + /** Hygraph Management API. **Only used for migrations.** */ + hygraphManagementApi?: InputMaybe; /** Hygraph Project ID. **Only used for migrations.** */ hygraphProjectId?: InputMaybe; /** @@ -448,6 +450,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject