@graphcommerce/hygraph-cli 9.0.4-canary.1 → 9.0.4-canary.11
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 +24 -0
- package/dist/index.js +928 -5
- package/package.json +17 -12
- package/tsconfig.json +2 -2
- package/dist/UpsertClient.js +0 -80
- package/dist/migrateHygraphCli.js +0 -88
- package/dist/migrationActionFactory.js +0 -133
- package/dist/migrations/graphcommerce5to6.js +0 -98
- package/dist/migrations/graphcommerce6to7.js +0 -206
- package/dist/migrations/graphcommerce7to8.js +0 -41
- package/dist/migrations/graphcommerce8to9.js +0 -68
- package/dist/migrations/index.js +0 -13
- package/dist/readSchema.js +0 -50
- package/dist/types.js +0 -2
- package/dist/utils/getConfig.js +0 -19
- package/dist/utils/getEndpointUrl.js +0 -43
- package/dist/utils/getManagementClient.js +0 -15
- package/dist/utils/graphCommerceLog.js +0 -15
package/package.json
CHANGED
|
@@ -2,17 +2,22 @@
|
|
|
2
2
|
"name": "@graphcommerce/hygraph-cli",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.4-canary.
|
|
5
|
+
"version": "9.0.4-canary.11",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
6
13
|
"scripts": {
|
|
7
|
-
"dev": "
|
|
8
|
-
"build": "
|
|
9
|
-
"prepack": "
|
|
14
|
+
"dev": "pkgroll --clean-dist --watch",
|
|
15
|
+
"build": "pkgroll --clean-dist",
|
|
16
|
+
"prepack": "pkgroll --clean-dist"
|
|
10
17
|
},
|
|
11
|
-
"type": "commonjs",
|
|
12
|
-
"main": "dist/index.js",
|
|
13
|
-
"types": "src/index.ts",
|
|
14
18
|
"dependencies": {
|
|
15
19
|
"@hygraph/management-sdk": "1.2.5",
|
|
20
|
+
"@types/prompts": "^2.4.9",
|
|
16
21
|
"@whatwg-node/fetch": "^0.10.1",
|
|
17
22
|
"graphql": "^16.10.0",
|
|
18
23
|
"graphql-tag": "^2.12.6",
|
|
@@ -20,14 +25,14 @@
|
|
|
20
25
|
},
|
|
21
26
|
"peerDependencies": {
|
|
22
27
|
"@apollo/client": "*",
|
|
23
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.4-canary.
|
|
24
|
-
"@graphcommerce/next-config": "^9.0.4-canary.
|
|
25
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.4-canary.
|
|
26
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.4-canary.
|
|
28
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.4-canary.11",
|
|
29
|
+
"@graphcommerce/next-config": "^9.0.4-canary.11",
|
|
30
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.4-canary.11",
|
|
31
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.4-canary.11",
|
|
27
32
|
"dotenv": "^16.1.4"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
|
-
"
|
|
35
|
+
"pkgroll": "^2.5.1",
|
|
31
36
|
"typescript": "5.7.2"
|
|
32
37
|
},
|
|
33
38
|
"sideEffects": false,
|
package/tsconfig.json
CHANGED
package/dist/UpsertClient.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UpsertClient = void 0;
|
|
4
|
-
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
-
class UpsertClient extends management_sdk_1.Client {
|
|
6
|
-
schema;
|
|
7
|
-
constructor(params, schema) {
|
|
8
|
-
super(params);
|
|
9
|
-
this.schema = schema;
|
|
10
|
-
}
|
|
11
|
-
/** @public */
|
|
12
|
-
upsertModel(data) {
|
|
13
|
-
const exists = this.schema.models.some((m) => m.apiId === data.apiId);
|
|
14
|
-
return exists ? this.createModel(data) : this.updateModel(data);
|
|
15
|
-
}
|
|
16
|
-
/** @public */
|
|
17
|
-
upsertComponent(data) {
|
|
18
|
-
const exists = this.schema.models.some((m) => m.apiId === data.apiId);
|
|
19
|
-
return exists ? this.createComponent(data) : this.updateComponent(data);
|
|
20
|
-
}
|
|
21
|
-
/** @public */
|
|
22
|
-
upsertSimpleField(data) {
|
|
23
|
-
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
24
|
-
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
25
|
-
return exists
|
|
26
|
-
? this.createSimpleField(data)
|
|
27
|
-
: this.updateSimpleField({ ...data, embeddableModels: undefined });
|
|
28
|
-
}
|
|
29
|
-
// upsertRemoteField(data: BatchMigrationCreateRemoteFieldInput) {
|
|
30
|
-
// const model = this.schema.models.find((m) => m.apiId === data.parentApiId)
|
|
31
|
-
// const exists = model?.fields.some((f) => f.apiId === data.apiId)
|
|
32
|
-
// return exists ? this.createRemoteField(data) : this.updateRemoteField(data)
|
|
33
|
-
// }
|
|
34
|
-
/** @public */
|
|
35
|
-
upsertRelationalField(data) {
|
|
36
|
-
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
37
|
-
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
38
|
-
return exists ? this.createRelationalField(data) : this.updateRelationalField(data);
|
|
39
|
-
}
|
|
40
|
-
/** @public */
|
|
41
|
-
upsertUnionField(data) {
|
|
42
|
-
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
43
|
-
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
44
|
-
return exists ? this.createUnionField(data) : this.updateUnionField(data);
|
|
45
|
-
}
|
|
46
|
-
/** @public */
|
|
47
|
-
upsertComponentField(data) {
|
|
48
|
-
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
49
|
-
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
50
|
-
return exists ? this.createComponentField(data) : this.updateComponentField(data);
|
|
51
|
-
}
|
|
52
|
-
/** @public */
|
|
53
|
-
upsertComponentUnionField(data) {
|
|
54
|
-
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
55
|
-
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
56
|
-
return exists ? this.createComponentUnionField(data) : this.updateComponentUnionField(data);
|
|
57
|
-
}
|
|
58
|
-
/** @public */
|
|
59
|
-
upsertEnumeration(data) {
|
|
60
|
-
const exists = this.schema.enumerations.some((e) => e.apiId === data.apiId);
|
|
61
|
-
return exists ? this.createEnumeration(data) : this.updateEnumeration(data);
|
|
62
|
-
}
|
|
63
|
-
/** @public */
|
|
64
|
-
upsertEnumerableField(data) {
|
|
65
|
-
const model = this.schema.models.find((m) => m.apiId === data.parentApiId);
|
|
66
|
-
const exists = model?.fields.some((f) => f.apiId === data.apiId);
|
|
67
|
-
return exists ? this.createEnumerableField(data) : this.updateEnumerableField(data);
|
|
68
|
-
}
|
|
69
|
-
/** @public */
|
|
70
|
-
upsertStage(data) {
|
|
71
|
-
const exists = this.schema.stages.some((m) => m.apiId === data.apiId);
|
|
72
|
-
return exists ? this.createStage(data) : this.updateStage(data);
|
|
73
|
-
}
|
|
74
|
-
/** @public */
|
|
75
|
-
upsertLocale(data) {
|
|
76
|
-
const exists = this.schema.locales.some((m) => m.apiId === data.apiId);
|
|
77
|
-
return exists ? this.createLocale(data) : this.updateLocale(data);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.UpsertClient = UpsertClient;
|
|
@@ -1,88 +0,0 @@
|
|
|
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.migrateHygraphCli = migrateHygraphCli;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const next_config_1 = require("@graphcommerce/next-config");
|
|
9
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
11
|
-
const migrations_1 = require("./migrations");
|
|
12
|
-
const readSchema_1 = require("./readSchema");
|
|
13
|
-
const UpsertClient_1 = require("./UpsertClient");
|
|
14
|
-
const getConfig_1 = require("./utils/getConfig");
|
|
15
|
-
const getEndpointUrl_1 = require("./utils/getEndpointUrl");
|
|
16
|
-
const getManagementClient_1 = require("./utils/getManagementClient");
|
|
17
|
-
const graphCommerceLog_1 = require("./utils/graphCommerceLog");
|
|
18
|
-
dotenv_1.default.config();
|
|
19
|
-
async function migrateHygraphCli() {
|
|
20
|
-
const hygraphConfig = (0, getConfig_1.getConfig)((0, next_config_1.loadConfig)(process.cwd()));
|
|
21
|
-
/**
|
|
22
|
-
* Extracting the current GC version. Are we gonna use the current version to determine which
|
|
23
|
-
* scripts should be runned? Or do we let the user pick the migration from a list? 🤔
|
|
24
|
-
*/
|
|
25
|
-
const packageJson = fs_1.default.readFileSync('package.json', 'utf8');
|
|
26
|
-
const packageData = JSON.parse(packageJson);
|
|
27
|
-
const graphcommerceVersion = packageData.dependencies['@graphcommerce/next-ui'];
|
|
28
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Graphcommerce version: ${graphcommerceVersion}`, 'info');
|
|
29
|
-
const mangementClient = (0, getManagementClient_1.getManagementClient)(hygraphConfig);
|
|
30
|
-
// Extract the currently existing models, components and enumerations from the Hygraph schema.
|
|
31
|
-
const schemaViewer = await (0, readSchema_1.readSchema)(mangementClient, hygraphConfig.projectId);
|
|
32
|
-
const schema = schemaViewer.viewer.project.environment.contentModel;
|
|
33
|
-
// A list of possible migrations
|
|
34
|
-
const possibleMigrations = Object.entries(migrations_1.availableMigrations);
|
|
35
|
-
// Here we setup the list we ask the user to choose from
|
|
36
|
-
const selectMigrationInput = {
|
|
37
|
-
type: 'select',
|
|
38
|
-
name: 'selectedMigration',
|
|
39
|
-
message: '\x1b[36m\x1b[1m[]: Select migration',
|
|
40
|
-
choices: possibleMigrations.map(([name, migration]) => ({
|
|
41
|
-
title: name,
|
|
42
|
-
value: { name, migration },
|
|
43
|
-
})),
|
|
44
|
-
};
|
|
45
|
-
// Here we ask the user to choose a migration from a list of possible migrations
|
|
46
|
-
try {
|
|
47
|
-
(0, graphCommerceLog_1.graphcommerceLog)('Available migrations: ', 'info');
|
|
48
|
-
const selectMigrationOutput = await (0, prompts_1.default)(selectMigrationInput);
|
|
49
|
-
let { migration, name } = selectMigrationOutput.selectedMigration;
|
|
50
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`You have selected the ${selectMigrationOutput.selectedMigration.name} migration`, 'info');
|
|
51
|
-
try {
|
|
52
|
-
const { endpoint, migrations } = await (0, getEndpointUrl_1.getEnvironment)(mangementClient, hygraphConfig);
|
|
53
|
-
const migrationExists = migrations.find((m) => m.name?.startsWith(name) && m.status === 'SUCCESS');
|
|
54
|
-
if (migrationExists) {
|
|
55
|
-
if (!process.argv.includes('--force')) {
|
|
56
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Migration ${name} as ${migrationExists.name} already exists in Hygraph with the status SUCCESS. To rerun this migration use the --force option. Exiting now..`, 'info');
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Migration ${name} as ${migrationExists.name} already exists in Hygraph with the status SUCCESS. Using --force, rerunning migration..`, 'warning');
|
|
61
|
-
}
|
|
62
|
-
name = `${name}-${Date.now()}`;
|
|
63
|
-
}
|
|
64
|
-
// Here we try to run the migration
|
|
65
|
-
const result = await migration(schema, new UpsertClient_1.UpsertClient({ authToken: hygraphConfig.authToken, endpoint, name }, schema));
|
|
66
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Migration result: ${JSON.stringify(result)}`, 'info');
|
|
67
|
-
if (!result) {
|
|
68
|
-
(0, graphCommerceLog_1.graphcommerceLog)('No migration client found. Please make sure your GC_HYGRAPH_WRITE_ACCESS_TOKEN in your env file is correct.');
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
if (result.status !== 'SUCCESS') {
|
|
72
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Migration not successful: ${result.status} ${name}:\n${result.errors}`);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Migration successful: ${name}`, 'info');
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
if (err instanceof Error) {
|
|
79
|
-
const garbledErrorIndex = err.message.indexOf(': {"');
|
|
80
|
-
const msg = garbledErrorIndex > 0 ? err.message.slice(0, garbledErrorIndex) : err.message;
|
|
81
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`${msg}`, 'error');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`An error occurred: ${error}`, 'error');
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
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.migrationActionFactory = migrationActionFactory;
|
|
7
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
const graphCommerceLog_1 = require("./utils/graphCommerceLog");
|
|
9
|
-
dotenv_1.default.config();
|
|
10
|
-
function migrationActionFactory(schema, client) {
|
|
11
|
-
/**
|
|
12
|
-
* This constant is used to assign the right action of the management SDK to the migratioAction
|
|
13
|
-
* function
|
|
14
|
-
*/
|
|
15
|
-
const actionMap = client
|
|
16
|
-
? {
|
|
17
|
-
create: {
|
|
18
|
-
model: (innerprops) => client.createModel(innerprops),
|
|
19
|
-
component: (innerprops) => client.createComponent(innerprops),
|
|
20
|
-
enumeration: (innerprops) => client.createEnumeration(innerprops),
|
|
21
|
-
simpleField: (innerprops) => client.createSimpleField(innerprops),
|
|
22
|
-
enumerableField: (innerprops) => client.createEnumerableField(innerprops),
|
|
23
|
-
componentField: (innerprops) => client.createComponentField(innerprops),
|
|
24
|
-
relationalField: (innerprops) => client.createRelationalField(innerprops),
|
|
25
|
-
unionField: (innerprops) => client.createUnionField(innerprops),
|
|
26
|
-
componentUnionField: (innerprops) => client.createComponentUnionField(innerprops),
|
|
27
|
-
},
|
|
28
|
-
update: {
|
|
29
|
-
model: (innerprops) => client.updateModel(innerprops),
|
|
30
|
-
component: (innerprops) => client.updateComponent(innerprops),
|
|
31
|
-
enumeration: (innerprops) => client.updateEnumeration(innerprops),
|
|
32
|
-
simpleField: (innerprops) => client.updateSimpleField(innerprops),
|
|
33
|
-
enumerableField: (innerprops) => client.updateEnumerableField(innerprops),
|
|
34
|
-
componentField: (innerprops) => client.updateComponentField(innerprops),
|
|
35
|
-
relationalField: (innerprops) => client.updateRelationalField(innerprops),
|
|
36
|
-
unionField: (innerprops) => client.updateUnionField(innerprops),
|
|
37
|
-
componentUnionField: (innerprops) => client.updateComponentUnionField(innerprops),
|
|
38
|
-
},
|
|
39
|
-
delete: {
|
|
40
|
-
model: (innerprops) => client.deleteModel(innerprops),
|
|
41
|
-
component: (innerprops) => client.deleteComponent(innerprops),
|
|
42
|
-
enumeration: (innerprops) => client.deleteEnumeration(innerprops),
|
|
43
|
-
simpleField: (innerprops) => client.deleteField(innerprops),
|
|
44
|
-
enumerableField: (innerprops) => client.deleteField(innerprops),
|
|
45
|
-
componentField: (innerprops) => client.deleteField(innerprops),
|
|
46
|
-
relationalField: (innerprops) => client.deleteField(innerprops),
|
|
47
|
-
unionField: (innerprops) => client.deleteField(innerprops),
|
|
48
|
-
componentUnionField: (innerprops) => client.deleteField(innerprops),
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
: undefined;
|
|
52
|
-
/**
|
|
53
|
-
* This function is our variation on the client.migrationAction functions from the hygraph
|
|
54
|
-
* management sdk.
|
|
55
|
-
*
|
|
56
|
-
* MigrationAction() is better suited because it is a single function for all actions. More
|
|
57
|
-
* importantly, if the action fails, because a field with the apiID already exists for instance.
|
|
58
|
-
* it will skip this action but still continue the whole migration, while the management sdk
|
|
59
|
-
* function will bail.
|
|
60
|
-
*
|
|
61
|
-
* It takes the schema as argument, which is always the same.
|
|
62
|
-
*
|
|
63
|
-
* Then it takes the type of schema entity you want to do an action upon, and the action you want
|
|
64
|
-
* to do.
|
|
65
|
-
*
|
|
66
|
-
* The fourth arguments are the props that belong to the action you want to do. For instance, if
|
|
67
|
-
* you want to create a model, you need to pass the props that belong to a model.
|
|
68
|
-
*
|
|
69
|
-
* The last two arguments are optional. If you want to create a field, you need to pass the apiId
|
|
70
|
-
* of the model or component you want to create the field on. If you want to create a field on a
|
|
71
|
-
* component, you also need to pass the parentType, which is either 'model' or 'component'.
|
|
72
|
-
*/
|
|
73
|
-
const migrationAction = (_schema, type, action, props, parentApiId, parentType) => {
|
|
74
|
-
/**
|
|
75
|
-
* Check if the entity already exists. If an update or deletion is made, it does not matter if
|
|
76
|
-
* the entity already exists
|
|
77
|
-
*/
|
|
78
|
-
const alreadyExists = () => {
|
|
79
|
-
if (action !== 'create') {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
switch (type) {
|
|
83
|
-
case 'model':
|
|
84
|
-
return schema.models.some((model) => model.apiId === props.apiId);
|
|
85
|
-
case 'component':
|
|
86
|
-
return schema.components.some((component) => component.apiId === props.apiId);
|
|
87
|
-
case 'enumeration':
|
|
88
|
-
return schema.enumerations.some((enumeration) => enumeration.apiId === props.apiId);
|
|
89
|
-
case 'simpleField':
|
|
90
|
-
case 'enumerableField':
|
|
91
|
-
case 'relationalField':
|
|
92
|
-
case 'unionField':
|
|
93
|
-
case 'componentUnionField': {
|
|
94
|
-
let parent;
|
|
95
|
-
switch (parentType) {
|
|
96
|
-
case 'model': {
|
|
97
|
-
parent = schema.models.find((model) => model.apiId === parentApiId);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
case 'component': {
|
|
101
|
-
parent = schema.components.find((component) => component.apiId === parentApiId);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
default:
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
return parent?.fields.some((field) => field.apiId === props.apiId);
|
|
108
|
-
}
|
|
109
|
-
default: {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const actionFunc = actionMap && actionMap[action] && actionMap[action][type];
|
|
115
|
-
if (!alreadyExists()) {
|
|
116
|
-
if (actionFunc) {
|
|
117
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`${(0, graphCommerceLog_1.capitalize)(action)} ${type} with apiId ${props.apiId}...`);
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
119
|
-
// @ts-ignore | This error is a loss on typescript autocomplete, but the function is called correctly
|
|
120
|
-
actionFunc(props);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`Action ${action} is not supported for ${type}`, 'error');
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
(0, graphCommerceLog_1.graphcommerceLog)(`${(0, graphCommerceLog_1.capitalize)(type)} with apiId ${props.apiId} on ${parentApiId} already exists`, 'warning');
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
return {
|
|
131
|
-
migrationAction,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
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 migrationActionFactory_1 = require("../migrationActionFactory");
|
|
6
|
-
const graphcommerce5to6 = async (schema, client) => {
|
|
7
|
-
const { migrationAction } = (0, migrationActionFactory_1.migrationActionFactory)(schema, client);
|
|
8
|
-
// ? ENUMERATIONS
|
|
9
|
-
migrationAction(schema, 'enumeration', 'create', {
|
|
10
|
-
displayName: 'Row Links Variants',
|
|
11
|
-
apiId: 'RowLinksVariants',
|
|
12
|
-
values: [
|
|
13
|
-
{ displayName: 'Inline', apiId: 'Inline' },
|
|
14
|
-
{ displayName: 'Image Label Swiper', apiId: 'ImageLabelSwiper' },
|
|
15
|
-
{ displayName: 'Logo Swiper', apiId: 'LogoSwiper' },
|
|
16
|
-
{ displayName: 'USPS', apiId: 'Usps' },
|
|
17
|
-
],
|
|
18
|
-
});
|
|
19
|
-
// ? MODEL
|
|
20
|
-
migrationAction(schema, 'model', 'create', {
|
|
21
|
-
apiId: 'RowLinks',
|
|
22
|
-
apiIdPlural: 'RowLinksMultiple',
|
|
23
|
-
displayName: 'Row Links',
|
|
24
|
-
description: 'Row Links is a Row of PageLinks with different variants',
|
|
25
|
-
});
|
|
26
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
27
|
-
displayName: 'Identity',
|
|
28
|
-
apiId: 'identity',
|
|
29
|
-
description: 'Only used for internal reference',
|
|
30
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
31
|
-
isTitle: true,
|
|
32
|
-
isRequired: true,
|
|
33
|
-
isUnique: true,
|
|
34
|
-
modelApiId: 'RowLinks',
|
|
35
|
-
}, 'RowLinks', 'model');
|
|
36
|
-
migrationAction(schema, 'enumerableField', 'create', {
|
|
37
|
-
displayName: 'Variant',
|
|
38
|
-
apiId: 'linksVariant',
|
|
39
|
-
parentApiId: 'RowLinks',
|
|
40
|
-
enumerationApiId: 'RowLinksVariants',
|
|
41
|
-
description: 'Different variants for Row Links',
|
|
42
|
-
}, 'RowLinks', 'model');
|
|
43
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
44
|
-
displayName: 'Title',
|
|
45
|
-
apiId: 'title',
|
|
46
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
47
|
-
isRequired: true,
|
|
48
|
-
modelApiId: 'RowLinks',
|
|
49
|
-
isLocalized: true,
|
|
50
|
-
}, 'RowLinks', 'model');
|
|
51
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
52
|
-
displayName: 'Copy',
|
|
53
|
-
apiId: 'rowLinksCopy',
|
|
54
|
-
type: management_sdk_1.SimpleFieldType.Richtext,
|
|
55
|
-
isLocalized: true,
|
|
56
|
-
modelApiId: 'RowLinks',
|
|
57
|
-
}, 'RowLinks', 'model');
|
|
58
|
-
migrationAction(schema, 'relationalField', 'create', {
|
|
59
|
-
displayName: 'Links',
|
|
60
|
-
apiId: 'pageLinks',
|
|
61
|
-
modelApiId: 'RowLinks',
|
|
62
|
-
type: management_sdk_1.RelationalFieldType.Relation,
|
|
63
|
-
reverseField: {
|
|
64
|
-
apiId: 'rowLinks',
|
|
65
|
-
modelApiId: 'PageLink',
|
|
66
|
-
displayName: 'RowLinks',
|
|
67
|
-
visibility: management_sdk_1.VisibilityTypes.Hidden,
|
|
68
|
-
isList: true,
|
|
69
|
-
},
|
|
70
|
-
visibility: management_sdk_1.VisibilityTypes.ReadWrite,
|
|
71
|
-
isList: true,
|
|
72
|
-
}, 'RowLinks', 'model');
|
|
73
|
-
migrationAction(schema, 'unionField', 'update', {
|
|
74
|
-
apiId: 'content',
|
|
75
|
-
displayName: 'Content',
|
|
76
|
-
modelApiId: 'Page',
|
|
77
|
-
reverseField: {
|
|
78
|
-
modelApiIds: [
|
|
79
|
-
'RowLinks',
|
|
80
|
-
'RowServiceOptions',
|
|
81
|
-
'RowSpecialBanner',
|
|
82
|
-
'RowQuote',
|
|
83
|
-
'RowProduct',
|
|
84
|
-
'RowColumnOne',
|
|
85
|
-
'RowColumnTwo',
|
|
86
|
-
'RowColumnThree',
|
|
87
|
-
'RowHeroBanner',
|
|
88
|
-
'RowBlogContent',
|
|
89
|
-
'RowButtonList',
|
|
90
|
-
'RowContentLinks',
|
|
91
|
-
'RowButtonLinkList',
|
|
92
|
-
],
|
|
93
|
-
// visibility: VisibilityTypes.Hidden, => Currently not supported for updateUnionField | https://github.com/hygraph/management-sdk/issues/34
|
|
94
|
-
},
|
|
95
|
-
}, 'Page', 'model');
|
|
96
|
-
return client.run(true);
|
|
97
|
-
};
|
|
98
|
-
exports.graphcommerce5to6 = graphcommerce5to6;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.graphcommerce6to7 = void 0;
|
|
4
|
-
const management_sdk_1 = require("@hygraph/management-sdk");
|
|
5
|
-
const migrationActionFactory_1 = require("../migrationActionFactory");
|
|
6
|
-
const graphcommerce6to7 = async (schema, client) => {
|
|
7
|
-
const { migrationAction } = (0, migrationActionFactory_1.migrationActionFactory)(schema, client);
|
|
8
|
-
// ? ENUMERATIONS
|
|
9
|
-
migrationAction(schema, 'enumeration', 'create', {
|
|
10
|
-
displayName: 'Row Column One Variants',
|
|
11
|
-
apiId: 'RowColumnOneVariants',
|
|
12
|
-
values: [
|
|
13
|
-
{ displayName: 'Default', apiId: 'Default' },
|
|
14
|
-
{ displayName: 'Message', apiId: 'Message' },
|
|
15
|
-
],
|
|
16
|
-
});
|
|
17
|
-
migrationAction(schema, 'enumeration', 'create', {
|
|
18
|
-
displayName: 'Dynamic Row Condition Number Operator',
|
|
19
|
-
apiId: 'DynamicRowConditionNumberOperator',
|
|
20
|
-
values: [
|
|
21
|
-
{ displayName: 'Greater than or equal to', apiId: 'GTE' },
|
|
22
|
-
{ displayName: 'Less than or equal to', apiId: 'LTE' },
|
|
23
|
-
{ displayName: 'Equal to', apiId: 'EQUAL' },
|
|
24
|
-
],
|
|
25
|
-
});
|
|
26
|
-
migrationAction(schema, 'enumeration', 'create', {
|
|
27
|
-
displayName: 'Dynamic Row Placement',
|
|
28
|
-
apiId: 'DynamicRowPlacement',
|
|
29
|
-
values: [
|
|
30
|
-
{ displayName: 'Before', apiId: 'BEFORE' },
|
|
31
|
-
{ displayName: 'After', apiId: 'AFTER' },
|
|
32
|
-
{ displayName: 'Replace', apiId: 'REPLACE' },
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
// ? COMPONENTS
|
|
36
|
-
migrationAction(schema, 'component', 'create', {
|
|
37
|
-
displayName: 'Text',
|
|
38
|
-
apiId: 'ConditionText',
|
|
39
|
-
apiIdPlural: 'ConditionTexts',
|
|
40
|
-
});
|
|
41
|
-
migrationAction(schema, 'component', 'create', {
|
|
42
|
-
displayName: 'Number',
|
|
43
|
-
apiId: 'ConditionNumber',
|
|
44
|
-
apiIdPlural: 'ConditionNumbers',
|
|
45
|
-
});
|
|
46
|
-
migrationAction(schema, 'component', 'create', {
|
|
47
|
-
displayName: 'AND',
|
|
48
|
-
apiId: 'ConditionAnd',
|
|
49
|
-
apiIdPlural: 'ConditionAnds',
|
|
50
|
-
description: 'All of these conditions must match',
|
|
51
|
-
});
|
|
52
|
-
migrationAction(schema, 'component', 'create', {
|
|
53
|
-
displayName: 'OR',
|
|
54
|
-
apiId: 'ConditionOr',
|
|
55
|
-
apiIdPlural: 'ConditionOrs',
|
|
56
|
-
description: 'One of these conditions must match',
|
|
57
|
-
});
|
|
58
|
-
migrationAction(schema, 'componentUnionField', 'create', {
|
|
59
|
-
displayName: 'Conditions',
|
|
60
|
-
apiId: 'conditions',
|
|
61
|
-
parentApiId: 'ConditionAnd',
|
|
62
|
-
componentApiIds: ['ConditionOr', 'ConditionText', 'ConditionNumber'],
|
|
63
|
-
isList: true,
|
|
64
|
-
}, 'ConditionAnd', 'component');
|
|
65
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
66
|
-
displayName: 'Property',
|
|
67
|
-
apiId: 'property',
|
|
68
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
69
|
-
parentApiId: 'ConditionText',
|
|
70
|
-
description: 'Path to the value of the object being evaluated.\n\nFor products: url_key, category, sku',
|
|
71
|
-
isRequired: true,
|
|
72
|
-
validations: {
|
|
73
|
-
String: {
|
|
74
|
-
matches: {
|
|
75
|
-
flags: ['i', 's'],
|
|
76
|
-
regex: '^[a-z0-9-_.]+$',
|
|
77
|
-
errorMessage: 'Only letters, numbers, dashes (-), underscores (_) or dots allowed (.)',
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
}, 'ConditionText', 'component');
|
|
82
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
83
|
-
displayName: 'Value',
|
|
84
|
-
apiId: 'value',
|
|
85
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
86
|
-
parentApiId: 'ConditionText',
|
|
87
|
-
isRequired: true,
|
|
88
|
-
}, 'ConditionText', 'component');
|
|
89
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
90
|
-
displayName: 'Property',
|
|
91
|
-
apiId: 'property',
|
|
92
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
93
|
-
parentApiId: 'ConditionNumber',
|
|
94
|
-
isRequired: true,
|
|
95
|
-
validations: {
|
|
96
|
-
String: {
|
|
97
|
-
matches: {
|
|
98
|
-
flags: ['i', 's'],
|
|
99
|
-
regex: '^[a-z0-9-_.]+$',
|
|
100
|
-
errorMessage: 'Only letters, numbers, dashes (-), underscores (_) or dots allowed (.)',
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
}, 'ConditionNumber', 'component');
|
|
105
|
-
migrationAction(schema, 'enumerableField', 'create', {
|
|
106
|
-
displayName: 'Operator',
|
|
107
|
-
apiId: 'operator',
|
|
108
|
-
parentApiId: 'ConditionNumber',
|
|
109
|
-
enumerationApiId: 'DynamicRowConditionNumberOperator',
|
|
110
|
-
isRequired: true,
|
|
111
|
-
}, 'ConditionNumber', 'component');
|
|
112
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
113
|
-
displayName: 'Value',
|
|
114
|
-
apiId: 'value',
|
|
115
|
-
type: management_sdk_1.SimpleFieldType.Float,
|
|
116
|
-
parentApiId: 'ConditionNumber',
|
|
117
|
-
isRequired: true,
|
|
118
|
-
}, 'ConditionNumber', 'component');
|
|
119
|
-
// ? MODEL
|
|
120
|
-
migrationAction(schema, 'model', 'create', {
|
|
121
|
-
displayName: 'Dynamic Row',
|
|
122
|
-
apiId: 'DynamicRow',
|
|
123
|
-
apiIdPlural: 'DynamicRows',
|
|
124
|
-
description: 'Dynamic rows allow you to add specific Row models to pages based on the properties of the page',
|
|
125
|
-
});
|
|
126
|
-
migrationAction(schema, 'simpleField', 'create', {
|
|
127
|
-
displayName: 'Internal name',
|
|
128
|
-
apiId: 'internalName',
|
|
129
|
-
description: 'Only used for internal reference',
|
|
130
|
-
type: management_sdk_1.SimpleFieldType.String,
|
|
131
|
-
isTitle: true,
|
|
132
|
-
isRequired: true,
|
|
133
|
-
isUnique: true,
|
|
134
|
-
modelApiId: 'DynamicRow',
|
|
135
|
-
}, 'DynamicRow', 'model');
|
|
136
|
-
migrationAction(schema, 'unionField', 'create', {
|
|
137
|
-
displayName: 'Row',
|
|
138
|
-
apiId: 'row',
|
|
139
|
-
reverseField: {
|
|
140
|
-
modelApiIds: ['RowQuote', 'RowLinks', 'RowColumnOne'],
|
|
141
|
-
apiId: 'dynamicRow',
|
|
142
|
-
displayName: 'DynamicRows',
|
|
143
|
-
visibility: management_sdk_1.VisibilityTypes.Hidden,
|
|
144
|
-
isList: true,
|
|
145
|
-
},
|
|
146
|
-
parentApiId: 'DynamicRow',
|
|
147
|
-
}, 'DynamicRow', 'model');
|
|
148
|
-
migrationAction(schema, 'enumerableField', 'create', {
|
|
149
|
-
displayName: 'Placement',
|
|
150
|
-
apiId: 'placement',
|
|
151
|
-
parentApiId: 'DynamicRow',
|
|
152
|
-
enumerationApiId: 'DynamicRowPlacement',
|
|
153
|
-
description: 'Where will the row be placed relative to the target',
|
|
154
|
-
isRequired: true,
|
|
155
|
-
}, 'DynamicRow', 'model');
|
|
156
|
-
migrationAction(schema, 'unionField', 'create', {
|
|
157
|
-
displayName: 'Placement target',
|
|
158
|
-
apiId: 'target',
|
|
159
|
-
description: 'Optional: When the target is left blank it will place the Dynamic Row on the start or end.',
|
|
160
|
-
reverseField: {
|
|
161
|
-
modelApiIds: [
|
|
162
|
-
'RowQuote',
|
|
163
|
-
'RowLinks',
|
|
164
|
-
'RowColumnOne',
|
|
165
|
-
'RowColumnTwo',
|
|
166
|
-
'RowColumnThree',
|
|
167
|
-
'RowServiceOptions',
|
|
168
|
-
'RowContentLinks',
|
|
169
|
-
'RowButtonLinkList',
|
|
170
|
-
'RowProduct',
|
|
171
|
-
'RowSpecialBanner',
|
|
172
|
-
'RowHeroBanner',
|
|
173
|
-
'RowBlogContent',
|
|
174
|
-
],
|
|
175
|
-
apiId: 'dynamicRowsTarget',
|
|
176
|
-
displayName: 'DynamicRowsTarget',
|
|
177
|
-
visibility: management_sdk_1.VisibilityTypes.Hidden,
|
|
178
|
-
isList: true,
|
|
179
|
-
},
|
|
180
|
-
parentApiId: 'DynamicRow',
|
|
181
|
-
}, 'DynamicRow', 'model');
|
|
182
|
-
migrationAction(schema, 'componentUnionField', 'create', {
|
|
183
|
-
displayName: 'Conditions (OR)',
|
|
184
|
-
apiId: 'conditions',
|
|
185
|
-
parentApiId: 'DynamicRow',
|
|
186
|
-
description: 'One of these conditions must match',
|
|
187
|
-
componentApiIds: ['ConditionAnd', 'ConditionText', 'ConditionNumber'],
|
|
188
|
-
isList: true,
|
|
189
|
-
}, 'DynamicRow', 'model');
|
|
190
|
-
// ? Row Column One
|
|
191
|
-
migrationAction(schema, 'enumerableField', 'create', {
|
|
192
|
-
displayName: 'Variant',
|
|
193
|
-
apiId: 'rowColumnOneVariant',
|
|
194
|
-
enumerationApiId: 'RowColumnOneVariants',
|
|
195
|
-
parentApiId: 'RowColumnOne',
|
|
196
|
-
}, 'RowColumnOne', 'model');
|
|
197
|
-
migrationAction(schema, 'componentUnionField', 'create', {
|
|
198
|
-
displayName: 'Conditions',
|
|
199
|
-
apiId: 'conditions',
|
|
200
|
-
parentApiId: 'ConditionOr',
|
|
201
|
-
componentApiIds: ['ConditionText', 'ConditionNumber'],
|
|
202
|
-
isList: true,
|
|
203
|
-
}, 'ConditionOr', 'component');
|
|
204
|
-
return client.run(true);
|
|
205
|
-
};
|
|
206
|
-
exports.graphcommerce6to7 = graphcommerce6to7;
|