@graphcommerce/hygraph-cli 7.0.0-canary.21 → 7.0.0

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 CHANGED
@@ -1,6 +1,190 @@
1
1
  # @graphcommerce/hygraph-cli
2
2
 
3
- ## 7.0.0-canary.21
3
+ ## 7.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#1912](https://github.com/graphcommerce-org/graphcommerce/pull/1912) [`a43d389e9`](https://github.com/graphcommerce-org/graphcommerce/commit/a43d389e956fe69b73238b12c98c781b7044e4bb) - Added dynamic rows feature ([@JoshuaS98](https://github.com/JoshuaS98))
8
+
9
+ ### Minor Changes
10
+
11
+ - [#1938](https://github.com/graphcommerce-org/graphcommerce/pull/1938) [`5aa6558a4`](https://github.com/graphcommerce-org/graphcommerce/commit/5aa6558a4e48d8d670284802fed65a934429b0ea) - Introduce hygraph-cli for schema migrations ([@JoshuaS98](https://github.com/JoshuaS98))
12
+
13
+ ### Patch Changes
14
+
15
+ - [#2012](https://github.com/graphcommerce-org/graphcommerce/pull/2012) [`1dbb3ae13`](https://github.com/graphcommerce-org/graphcommerce/commit/1dbb3ae13553992ee1ed77f375375560f28c418c) - Upgrade graphql to 16.7.1, add graphql as peer dependency ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
16
+
17
+ - [#1924](https://github.com/graphcommerce-org/graphcommerce/pull/1924) [`04581f619`](https://github.com/graphcommerce-org/graphcommerce/commit/04581f619c609f2f6ca5268ee5effb6a1db3f0eb) - Use the latest branch from graphql-mesh so that all versions are in sync ([@paales](https://github.com/paales))
18
+
19
+ - [#1960](https://github.com/graphcommerce-org/graphcommerce/pull/1960) [`86e14569b`](https://github.com/graphcommerce-org/graphcommerce/commit/86e14569b1f68f73be7f93b614e36b382c5debff) - Updated to the latest release of GraphQL codegen and solve compatibility issues with our own generator ([@paales](https://github.com/paales))
20
+
21
+ ## 6.2.0-canary.98
22
+
23
+ ## 6.2.0-canary.97
24
+
25
+ ## 6.2.0-canary.96
26
+
27
+ ## 6.2.0-canary.95
28
+
29
+ ## 6.2.0-canary.94
30
+
31
+ ## 6.2.0-canary.93
32
+
33
+ ## 6.2.0-canary.92
34
+
35
+ ## 6.2.0-canary.91
36
+
37
+ ## 6.2.0-canary.90
38
+
39
+ ## 6.2.0-canary.89
40
+
41
+ ## 6.2.0-canary.88
42
+
43
+ ## 6.2.0-canary.87
44
+
45
+ ## 6.2.0-canary.86
46
+
47
+ ## 6.2.0-canary.85
48
+
49
+ ## 6.2.0-canary.84
50
+
51
+ ## 6.2.0-canary.83
52
+
53
+ ### Minor Changes
54
+
55
+ - [#1938](https://github.com/graphcommerce-org/graphcommerce/pull/1938) [`5aa6558a4`](https://github.com/graphcommerce-org/graphcommerce/commit/5aa6558a4e48d8d670284802fed65a934429b0ea) - Introduce hygraph-cli for schema migrations ([@JoshuaS98](https://github.com/JoshuaS98))
56
+
57
+ ## 6.2.0-canary.82
58
+
59
+ ## 6.2.0-canary.81
60
+
61
+ ## 6.2.0-canary.80
62
+
63
+ ## 6.2.0-canary.79
64
+
65
+ ## 6.2.0-canary.78
66
+
67
+ ## 6.2.0-canary.77
68
+
69
+ ## 6.2.0-canary.76
70
+
71
+ ## 6.2.0-canary.75
72
+
73
+ ## 6.2.0-canary.74
74
+
75
+ ## 6.2.0-canary.73
76
+
77
+ ## 6.2.0-canary.72
78
+
79
+ ## 6.2.0-canary.71
80
+
81
+ ## 6.2.0-canary.70
82
+
83
+ ## 6.2.0-canary.69
84
+
85
+ ### Patch Changes
86
+
87
+ - [#2012](https://github.com/graphcommerce-org/graphcommerce/pull/2012) [`1dbb3ae13`](https://github.com/graphcommerce-org/graphcommerce/commit/1dbb3ae13553992ee1ed77f375375560f28c418c) - Upgrade graphql to 16.7.1, add graphql as peer dependency ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
88
+
89
+ ## 6.2.0-canary.68
90
+
91
+ ## 6.2.0-canary.67
92
+
93
+ ## 6.2.0-canary.66
94
+
95
+ ## 6.2.0-canary.65
96
+
97
+ ## 6.2.0-canary.64
98
+
99
+ ## 6.2.0-canary.63
100
+
101
+ ## 6.2.0-canary.62
102
+
103
+ ## 6.2.0-canary.61
104
+
105
+ ## 6.2.0-canary.60
106
+
107
+ ## 6.2.0-canary.59
108
+
109
+ ## 6.2.0-canary.58
110
+
111
+ ## 6.2.0-canary.57
112
+
113
+ ## 6.2.0-canary.56
114
+
115
+ ## 6.2.0-canary.55
116
+
117
+ ## 6.2.0-canary.54
118
+
119
+ ## 6.2.0-canary.53
120
+
121
+ ## 6.2.0-canary.52
122
+
123
+ ## 6.2.0-canary.51
124
+
125
+ ## 6.2.0-canary.50
126
+
127
+ ## 6.2.0-canary.49
128
+
129
+ ## 6.2.0-canary.48
130
+
131
+ ## 6.2.0-canary.47
132
+
133
+ ## 6.2.0-canary.46
134
+
135
+ ## 6.2.0-canary.45
136
+
137
+ ## 6.2.0-canary.44
138
+
139
+ ## 6.2.0-canary.43
140
+
141
+ ## 6.2.0-canary.42
142
+
143
+ ## 6.2.0-canary.41
144
+
145
+ ### Patch Changes
146
+
147
+ - [#1960](https://github.com/graphcommerce-org/graphcommerce/pull/1960) [`86e14569b`](https://github.com/graphcommerce-org/graphcommerce/commit/86e14569b1f68f73be7f93b614e36b382c5debff) - Updated to the latest release of GraphQL codegen and solve compatibility issues with our own generator ([@paales](https://github.com/paales))
148
+
149
+ ## 6.2.0-canary.40
150
+
151
+ ## 6.2.0-canary.39
152
+
153
+ ## 6.2.0-canary.38
154
+
155
+ ## 6.2.0-canary.37
156
+
157
+ ## 6.2.0-canary.36
158
+
159
+ ## 6.2.0-canary.35
160
+
161
+ ## 6.2.0-canary.34
162
+
163
+ ## 6.2.0-canary.33
164
+
165
+ ## 6.2.0-canary.32
166
+
167
+ ## 6.2.0-canary.31
168
+
169
+ ## 6.2.0-canary.30
170
+
171
+ ## 6.2.0-canary.29
172
+
173
+ ## 6.2.0-canary.28
174
+
175
+ ## 6.2.0-canary.27
176
+
177
+ ## 6.2.0-canary.26
178
+
179
+ ## 6.2.0-canary.25
180
+
181
+ ## 6.2.0-canary.24
182
+
183
+ ## 6.2.0-canary.23
184
+
185
+ ## 6.2.0-canary.22
186
+
187
+ ## 6.2.0-canary.21
4
188
 
5
189
  ## 6.2.0-canary.20
6
190
 
package/Config.graphqls CHANGED
@@ -26,6 +26,12 @@ extend input GraphCommerceConfig {
26
26
  - Delete existing components
27
27
  - Update remote sources
28
28
  - Delete remote sources
29
+ - Read existing environments
30
+ - Read public content views
31
+ - Create public content views
32
+ - Update public content views
33
+ - Delete public content views
34
+ - Can see schema view
29
35
 
30
36
  ```
31
37
  GC_HYGRAPH_WRITE_ACCESS_ENDPOINT="https://...hygraph.com/v2/..."
@@ -34,4 +40,9 @@ extend input GraphCommerceConfig {
34
40
  ```
35
41
  """
36
42
  hygraphWriteAccessToken: String
43
+
44
+ """
45
+ Hygraph Project ID. **Only used for migrations.**
46
+ """
47
+ hygraphProjectId: String
37
48
  }
package/dist/client.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initClient = void 0;
4
+ const management_sdk_1 = require("@hygraph/management-sdk");
5
+ const log_functions_1 = require("./log-functions");
6
+ const initClient = (config, name) => {
7
+ if (!config.hygraphWriteAccessEndpoint) {
8
+ (0, log_functions_1.graphcommerceLog)('Please provide hygraphWriteAccessEndpoint in your config or GC_HYGRAPH_WRITE_ACCESS_ENDPOINT in your env file', 'error');
9
+ return 0;
10
+ }
11
+ if (!config.hygraphWriteAccessToken) {
12
+ (0, log_functions_1.graphcommerceLog)('Please provide GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file');
13
+ return 0;
14
+ }
15
+ return new management_sdk_1.Client({
16
+ authToken: config.hygraphWriteAccessToken,
17
+ endpoint: config.hygraphWriteAccessEndpoint,
18
+ name,
19
+ });
20
+ };
21
+ exports.initClient = initClient;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphcommerceLog = exports.capitalize = void 0;
4
+ const capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
5
+ exports.capitalize = capitalize;
6
+ const graphcommerceLog = (message, type) => {
7
+ const color = {
8
+ error: '\x1b[31m\x1b[1m%s\x1b[0m',
9
+ warning: '\x1b[33m\x1b[1m%s\x1b[0m',
10
+ info: '\x1b[36m\x1b[1m%s\x1b[0m',
11
+ };
12
+ // eslint-disable-next-line no-console
13
+ console.log(type ? color[type] : '', `[GraphCommerce]: ${message}`);
14
+ };
15
+ exports.graphcommerceLog = graphcommerceLog;
@@ -1,68 +1,96 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.migrateHygraph = void 0;
7
- /* eslint-disable no-console */
8
- /* eslint-disable import/no-extraneous-dependencies */
9
- const readline_1 = __importDefault(require("readline"));
10
- const dynamicRow_1 = require("./migrations/dynamicRow");
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const next_config_1 = require("@graphcommerce/next-config");
32
+ const dotenv_1 = __importDefault(require("dotenv"));
33
+ const prompts_1 = __importDefault(require("prompts"));
34
+ const log_functions_1 = require("./log-functions");
35
+ const migrations = __importStar(require("./migrations"));
36
+ const readSchema_1 = require("./readSchema");
37
+ dotenv_1.default.config();
11
38
  async function migrateHygraph() {
12
- let forceRun = false;
13
- // Interface to determine if force run should be enabled
14
- readline_1.default.createInterface({
15
- input: process.stdin,
16
- output: process.stdout,
17
- });
18
- const affirmativeAnswers = ['y', 'yes', 'Y', 'YES'];
19
- const handleKeypress = (key) => {
20
- if (affirmativeAnswers.includes(key.toLowerCase())) {
21
- console.log('\nForce run enabled');
22
- forceRun = true;
23
- }
24
- else {
25
- console.log('\nForce run disabled');
26
- forceRun = false;
27
- }
28
- process.stdin.pause();
39
+ const config = (0, next_config_1.loadConfig)(process.cwd());
40
+ /**
41
+ * Extracting the current GC version. Are we gonna use the current version to determine which
42
+ * scripts should be runned? Or do we let the user pick the migration from a list? 🤔
43
+ */
44
+ const packageJson = fs_1.default.readFileSync('package.json', 'utf8');
45
+ const packageData = JSON.parse(packageJson);
46
+ const graphcommerceVersion = packageData.dependencies['@graphcommerce/next-ui'];
47
+ (0, log_functions_1.graphcommerceLog)(`Graphcommerce version: ${graphcommerceVersion}`, 'info');
48
+ // Extract the currently existing models, components and enumerations from the Hygraph schema.
49
+ const schemaViewer = await (0, readSchema_1.readSchema)(config);
50
+ const schema = schemaViewer.viewer.project.environment.contentModel;
51
+ // A list of possible migrations
52
+ const possibleMigrations = Object.entries(migrations);
53
+ // Here we setup the list we ask the user to choose from
54
+ const selectMigrationInput = {
55
+ type: 'select',
56
+ name: 'selectedMigration',
57
+ message: '\x1b[36m\x1b[1m[GraphCommerce]: Select migration',
58
+ choices: [],
29
59
  };
30
- // Listen for keypress events
31
- process.stdin.on('keypress', handleKeypress);
32
- process.stdin.setRawMode(true);
33
- process.stdin.resume();
34
- console.log('Enable force run? (y/n)');
35
- // Wait for input
36
- await new Promise((resolve) => {
37
- process.stdin.once('data', () => {
38
- // Stop listening for input
39
- process.stdin.removeListener('keypress', handleKeypress);
40
- process.stdin.setRawMode(false);
41
- resolve();
42
- });
43
- });
44
- // TODO: Choose migration
45
- // TODO: GC-Version based migration
46
- const possibleMigrations = [
47
- ['add_dynamic_rows', dynamicRow_1.dynamicRow],
48
- ];
49
60
  for (const [name, migration] of possibleMigrations) {
61
+ if (Array.isArray(selectMigrationInput.choices)) {
62
+ selectMigrationInput?.choices?.push({ title: name, value: { name, migration } });
63
+ }
64
+ }
65
+ // Here we ask the user to choose a migration from a list of possible migrations
66
+ try {
67
+ (0, log_functions_1.graphcommerceLog)('Available migrations: ', 'info');
68
+ const selectMigrationOutput = await (0, prompts_1.default)(selectMigrationInput);
69
+ const { migration, name } = selectMigrationOutput.selectedMigration;
70
+ (0, log_functions_1.graphcommerceLog)(`You have selected the ${selectMigrationOutput.selectedMigration.name} migration`, 'info');
50
71
  try {
72
+ // Here we try to run the migration
51
73
  // eslint-disable-next-line no-await-in-loop
52
- const result = await migration(forceRun ? undefined : name);
53
- console.log(result);
74
+ const result = await migration(schema);
75
+ (0, log_functions_1.graphcommerceLog)(`Migration result: ${JSON.stringify(result)}`, 'info');
76
+ if (!result) {
77
+ throw new Error('[GraphCommerce]: No migration client found. Please make sure your GC_HYGRAPH_WRITE_ACCESS_ENDPOINT and GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file are correct.');
78
+ }
54
79
  if (result.status !== 'SUCCESS') {
55
- throw new Error(`Migration not successful: ${result.status} ${name}:\n${result.errors}`);
80
+ throw new Error(`[GraphCommerce]: Migration not successful: ${result.status} ${name}:\n${result.errors}`);
56
81
  }
57
- console.log(`Migration successful: ${name}`);
82
+ (0, log_functions_1.graphcommerceLog)(`Migration successful: ${name}`, 'info');
58
83
  }
59
84
  catch (err) {
60
85
  if (err instanceof Error) {
61
86
  const garbledErrorIndex = err.message.indexOf(': {"');
62
87
  const msg = garbledErrorIndex > 0 ? err.message.slice(0, garbledErrorIndex) : err.message;
63
- console.error(msg);
88
+ (0, log_functions_1.graphcommerceLog)(`${msg}`, 'error');
64
89
  }
65
90
  }
66
91
  }
92
+ catch (error) {
93
+ (0, log_functions_1.graphcommerceLog)(`[GraphCommerce]: An error occurred: ${error}`, 'error');
94
+ }
67
95
  }
68
96
  exports.migrateHygraph = migrateHygraph;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.migrationAction = exports.client = void 0;
7
+ const next_config_1 = require("@graphcommerce/next-config");
8
+ const dotenv_1 = __importDefault(require("dotenv"));
9
+ const client_1 = require("./client");
10
+ const log_functions_1 = require("./log-functions");
11
+ dotenv_1.default.config();
12
+ const config = (0, next_config_1.loadConfig)(process.cwd());
13
+ exports.client = (0, client_1.initClient)(config, undefined);
14
+ /**
15
+ * This constant is used to assign the right action of the management SDK to the migratioAction
16
+ * function
17
+ */
18
+ const actionMap = exports.client
19
+ ? {
20
+ create: {
21
+ model: (innerprops) => exports.client.createModel(innerprops),
22
+ component: (innerprops) => exports.client.createComponent(innerprops),
23
+ enumeration: (innerprops) => exports.client.createEnumeration(innerprops),
24
+ simpleField: (innerprops) => exports.client.createSimpleField(innerprops),
25
+ enumerableField: (innerprops) => exports.client.createEnumerableField(innerprops),
26
+ componentField: (innerprops) => exports.client.createComponentField(innerprops),
27
+ relationalField: (innerprops) => exports.client.createRelationalField(innerprops),
28
+ unionField: (innerprops) => exports.client.createUnionField(innerprops),
29
+ componentUnionField: (innerprops) => exports.client.createComponentUnionField(innerprops),
30
+ },
31
+ update: {
32
+ model: (innerprops) => exports.client.updateModel(innerprops),
33
+ component: (innerprops) => exports.client.updateComponent(innerprops),
34
+ enumeration: (innerprops) => exports.client.updateEnumeration(innerprops),
35
+ simpleField: (innerprops) => exports.client.updateSimpleField(innerprops),
36
+ enumerableField: (innerprops) => exports.client.updateEnumerableField(innerprops),
37
+ componentField: (innerprops) => exports.client.updateComponentField(innerprops),
38
+ relationalField: (innerprops) => exports.client.updateRelationalField(innerprops),
39
+ unionField: (innerprops) => exports.client.updateUnionField(innerprops),
40
+ componentUnionField: (innerprops) => exports.client.updateComponentUnionField(innerprops),
41
+ },
42
+ delete: {
43
+ model: (innerprops) => exports.client.deleteModel(innerprops),
44
+ component: (innerprops) => exports.client.deleteComponent(innerprops),
45
+ enumeration: (innerprops) => exports.client.deleteEnumeration(innerprops),
46
+ simpleField: (innerprops) => exports.client.deleteField(innerprops),
47
+ enumerableField: (innerprops) => exports.client.deleteField(innerprops),
48
+ componentField: (innerprops) => exports.client.deleteField(innerprops),
49
+ relationalField: (innerprops) => exports.client.deleteField(innerprops),
50
+ unionField: (innerprops) => exports.client.deleteField(innerprops),
51
+ componentUnionField: (innerprops) => exports.client.deleteField(innerprops),
52
+ },
53
+ }
54
+ : undefined;
55
+ /**
56
+ * This function is our variation on the client.migrationAction functions from the hygraph
57
+ * management sdk.
58
+ *
59
+ * MigrationAction() is better suited because it is a single function for all actions. More
60
+ * importantly, if the action fails, because a field with the apiID already exists for instance. it
61
+ * will skip this action but still continue the whole migration, while the management sdk function
62
+ * will bail.
63
+ *
64
+ * It takes the schema as argument, which is always the same.
65
+ *
66
+ * Then it takes the type of schema entity you want to do an action upon, and the action you want to
67
+ * do.
68
+ *
69
+ * The fourth arguments are the props that belong to the action you want to do. For instance, if you
70
+ * want to create a model, you need to pass the props that belong to a model.
71
+ *
72
+ * The last two arguments are optional. If you want to create a field, you need to pass the apiId of
73
+ * the model or component you want to create the field on. If you want to create a field on a
74
+ * component, you also need to pass the parentType, which is either 'model' or 'component'.
75
+ */
76
+ const migrationAction = (schema, type, action, props, parentApiId, parentType) => {
77
+ // Check if the entity already exists
78
+ const alreadyExists = () => {
79
+ switch (type) {
80
+ case 'model':
81
+ return schema.models.some((model) => model.apiId === props.apiId);
82
+ case 'component':
83
+ return schema.components.some((component) => component.apiId === props.apiId);
84
+ case 'enumeration':
85
+ return schema.enumerations.some((enumeration) => enumeration.apiId === props.apiId);
86
+ case 'simpleField':
87
+ case 'enumerableField':
88
+ case 'relationalField':
89
+ case 'unionField':
90
+ case 'componentUnionField': {
91
+ let parent;
92
+ switch (parentType) {
93
+ case 'model': {
94
+ parent = schema.models.find((model) => model.apiId === parentApiId);
95
+ break;
96
+ }
97
+ case 'component': {
98
+ parent = schema.components.find((component) => component.apiId === parentApiId);
99
+ break;
100
+ }
101
+ default:
102
+ return false; // or undefined or any other value you want if no match
103
+ }
104
+ return parent?.fields.some((field) => field.apiId === props.apiId);
105
+ }
106
+ default: {
107
+ return false; // or undefined or any other value you want if no match
108
+ }
109
+ }
110
+ };
111
+ const actionFunc = actionMap && actionMap[action] && actionMap[action][type];
112
+ if (!alreadyExists()) {
113
+ if (actionFunc) {
114
+ (0, log_functions_1.graphcommerceLog)(`${(0, log_functions_1.capitalize)(action)} ${type} with apiId ${props.apiId}...`);
115
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
116
+ // @ts-ignore | This error is a loss on typescript autocomplete, but the function is called correctly
117
+ actionFunc(props);
118
+ }
119
+ else {
120
+ (0, log_functions_1.graphcommerceLog)(`Action ${action} is not supported for ${type}`, 'error');
121
+ }
122
+ }
123
+ else {
124
+ (0, log_functions_1.graphcommerceLog)(`${(0, log_functions_1.capitalize)(type)} with apiId ${props.apiId} on ${parentApiId} already exists`, 'warning');
125
+ }
126
+ };
127
+ exports.migrationAction = migrationAction;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.graphcommerce5to6 = void 0;
4
+ const management_sdk_1 = require("@hygraph/management-sdk");
5
+ const migrationAction_1 = require("../migrationAction");
6
+ const graphcommerce5to6 = async (schema) => {
7
+ if (!migrationAction_1.client) {
8
+ return 0;
9
+ }
10
+ // ? ENUMERATIONS
11
+ (0, migrationAction_1.migrationAction)(schema, 'enumeration', 'create', {
12
+ displayName: 'Row Links Variants',
13
+ apiId: 'RowLinksVariants',
14
+ values: [
15
+ { displayName: 'Inline', apiId: 'Inline' },
16
+ { displayName: 'Image Label Swiper', apiId: 'ImageLabelSwiper' },
17
+ { displayName: 'Logo Swiper', apiId: 'LogoSwiper' },
18
+ { displayName: 'USPS', apiId: 'Usps' },
19
+ ],
20
+ });
21
+ // ? MODEL
22
+ (0, migrationAction_1.migrationAction)(schema, 'model', 'create', {
23
+ apiId: 'RowLinks',
24
+ apiIdPlural: 'RowLinksMultiple',
25
+ displayName: 'Row Links',
26
+ description: 'Row Links is a Row of PageLinks with different variants',
27
+ });
28
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
29
+ displayName: 'Identity',
30
+ apiId: 'identity',
31
+ description: 'Only used for internal reference',
32
+ type: management_sdk_1.SimpleFieldType.String,
33
+ isTitle: true,
34
+ isRequired: true,
35
+ isUnique: true,
36
+ modelApiId: 'RowLinks',
37
+ }, 'RowLinks', 'model');
38
+ (0, migrationAction_1.migrationAction)(schema, 'enumerableField', 'create', {
39
+ displayName: 'Variant',
40
+ apiId: 'linksVariant',
41
+ parentApiId: 'RowLinks',
42
+ enumerationApiId: 'RowLinksVariants',
43
+ description: 'Different variants for Row Links',
44
+ }, 'RowLinks', 'model');
45
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
46
+ displayName: 'Title',
47
+ apiId: 'title',
48
+ type: management_sdk_1.SimpleFieldType.String,
49
+ isRequired: true,
50
+ modelApiId: 'RowLinks',
51
+ isLocalized: true,
52
+ }, 'RowLinks', 'model');
53
+ (0, migrationAction_1.migrationAction)(schema, 'simpleField', 'create', {
54
+ displayName: 'Copy',
55
+ apiId: 'rowLinksCopy',
56
+ type: management_sdk_1.SimpleFieldType.Richtext,
57
+ isLocalized: true,
58
+ modelApiId: 'RowLinks',
59
+ }, 'RowLinks', 'model');
60
+ (0, migrationAction_1.migrationAction)(schema, 'relationalField', 'create', {
61
+ displayName: 'Links',
62
+ apiId: 'pageLinks',
63
+ modelApiId: 'RowLinks',
64
+ type: management_sdk_1.RelationalFieldType.Relation,
65
+ reverseField: {
66
+ apiId: 'rowLinks',
67
+ modelApiId: 'PageLink',
68
+ displayName: 'RowLinks',
69
+ visibility: management_sdk_1.VisibilityTypes.Hidden,
70
+ isList: true,
71
+ },
72
+ visibility: management_sdk_1.VisibilityTypes.ReadWrite,
73
+ isList: true,
74
+ }, 'RowLinks', 'model');
75
+ (0, migrationAction_1.migrationAction)(schema, 'unionField', 'update', {
76
+ apiId: 'content',
77
+ displayName: 'Content',
78
+ modelApiId: 'Page',
79
+ reverseField: {
80
+ modelApiIds: [
81
+ 'RowLinks',
82
+ 'RowServiceOptions',
83
+ 'RowSpecialBanner',
84
+ 'RowQuote',
85
+ 'RowProduct',
86
+ 'RowColumnOne',
87
+ 'RowColumnTwo',
88
+ 'RowColumnThree',
89
+ 'RowHeroBanner',
90
+ 'RowBlogContent',
91
+ 'RowButtonList',
92
+ 'RowContentLinks',
93
+ 'RowButtonLinkList',
94
+ ],
95
+ // visibility: VisibilityTypes.Hidden, => Currently not supported for updateUnionField | https://github.com/hygraph/management-sdk/issues/34
96
+ },
97
+ }, 'Page', 'model');
98
+ return migrationAction_1.client.run(true);
99
+ };
100
+ exports.graphcommerce5to6 = graphcommerce5to6;