@graphcommerce/hygraph-cli 9.0.4-canary.0 → 9.0.4-canary.10
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 +19 -7
- package/dist/index.js +928 -5
- package/package.json +17 -12
- package/src/migrationActionFactory.ts +11 -11
- 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.10",
|
|
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.10",
|
|
29
|
+
"@graphcommerce/next-config": "^9.0.4-canary.10",
|
|
30
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.4-canary.10",
|
|
31
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.4-canary.10",
|
|
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,
|
|
@@ -136,20 +136,20 @@ export function migrationActionFactory(schema: Schema, client: Client) {
|
|
|
136
136
|
* management sdk.
|
|
137
137
|
*
|
|
138
138
|
* MigrationAction() is better suited because it is a single function for all actions. More
|
|
139
|
-
* importantly, if the action fails, because a field with the apiID already exists for instance.
|
|
140
|
-
* will skip this action but still continue the whole migration, while the management sdk
|
|
141
|
-
* will bail.
|
|
139
|
+
* importantly, if the action fails, because a field with the apiID already exists for instance.
|
|
140
|
+
* it will skip this action but still continue the whole migration, while the management sdk
|
|
141
|
+
* function will bail.
|
|
142
142
|
*
|
|
143
143
|
* It takes the schema as argument, which is always the same.
|
|
144
144
|
*
|
|
145
|
-
* Then it takes the type of schema entity you want to do an action upon, and the action you want
|
|
146
|
-
* do.
|
|
145
|
+
* Then it takes the type of schema entity you want to do an action upon, and the action you want
|
|
146
|
+
* to do.
|
|
147
147
|
*
|
|
148
|
-
* The fourth arguments are the props that belong to the action you want to do. For instance, if
|
|
149
|
-
* want to create a model, you need to pass the props that belong to a model.
|
|
148
|
+
* The fourth arguments are the props that belong to the action you want to do. For instance, if
|
|
149
|
+
* you want to create a model, you need to pass the props that belong to a model.
|
|
150
150
|
*
|
|
151
|
-
* The last two arguments are optional. If you want to create a field, you need to pass the apiId
|
|
152
|
-
* the model or component you want to create the field on. If you want to create a field on a
|
|
151
|
+
* The last two arguments are optional. If you want to create a field, you need to pass the apiId
|
|
152
|
+
* of the model or component you want to create the field on. If you want to create a field on a
|
|
153
153
|
* component, you also need to pass the parentType, which is either 'model' or 'component'.
|
|
154
154
|
*/
|
|
155
155
|
const migrationAction = (
|
|
@@ -161,8 +161,8 @@ export function migrationActionFactory(schema: Schema, client: Client) {
|
|
|
161
161
|
parentType?: 'model' | 'component' | 'enumeration',
|
|
162
162
|
) => {
|
|
163
163
|
/**
|
|
164
|
-
* Check if the entity already exists.
|
|
165
|
-
*
|
|
164
|
+
* Check if the entity already exists. If an update or deletion is made, it does not matter if
|
|
165
|
+
* the entity already exists
|
|
166
166
|
*/
|
|
167
167
|
const alreadyExists = () => {
|
|
168
168
|
if (action !== 'create') {
|
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. it
|
|
58
|
-
* will skip this action but still continue the whole migration, while the management sdk function
|
|
59
|
-
* 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 to
|
|
64
|
-
* do.
|
|
65
|
-
*
|
|
66
|
-
* The fourth arguments are the props that belong to the action you want to do. For instance, if you
|
|
67
|
-
* 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 of
|
|
70
|
-
* 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.
|
|
76
|
-
* If an update or deletion is made, it does not matter if 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;
|