@graphql-hive/cli
Version:
A CLI util to manage and control your GraphQL Hive
98 lines • 3.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const base_command_1 = tslib_1.__importDefault(require("../../base-command"));
const config_1 = require("../../helpers/config");
const operations_1 = require("../../helpers/operations");
class OperationsPublish extends base_command_1.default {
async run() {
try {
const { flags, args } = await this.parse(OperationsPublish);
await this.require(flags);
const registry = this.ensure({
key: 'registry',
args: flags,
defaultValue: config_1.graphqlEndpoint,
env: 'HIVE_REGISTRY',
});
const file = args.file;
const token = this.ensure({
key: 'token',
args: flags,
env: 'HIVE_TOKEN',
});
let operations = await (0, operations_1.loadOperations)(file, {
normalize: true,
});
const collectedOperationsTotal = operations.length;
const noMissingHashes = operations.some(op => op.operationHash);
if (noMissingHashes) {
const comparisonResult = await this.registryApi(registry, token).comparePersistedOperations({
hashes: operations.map(op => op.operationHash),
});
const operationsToPublish = comparisonResult.comparePersistedOperations;
operations = operations.filter(op => operationsToPublish.includes(op.operationHash));
}
const unchangedTotal = collectedOperationsTotal - operations.length;
if (!operations.length) {
return this.success([
`Nothing to publish`,
'',
` Total: ${collectedOperationsTotal}`,
` Unchanged: ${unchangedTotal}`,
'',
].join('\n'));
}
const result = await this.registryApi(registry, token).publishPersistedOperations({
input: operations,
});
if (result.publishPersistedOperations) {
const summary = result.publishPersistedOperations.summary;
this.success([
'Operations successfully published!',
'',
` Total: ${summary.total}`,
` Unchanged: ${summary.unchanged}`,
'',
].join('\n'));
}
else {
this.error('OOPS! An error occurred in publishing the operation(s)');
}
}
catch (error) {
if (error instanceof core_1.Errors.ExitError) {
throw error;
}
else {
this.fail('Failed to publish operations');
this.handleFetchError(error);
}
}
}
}
OperationsPublish.description = 'saves operations to the store';
OperationsPublish.flags = {
registry: core_1.Flags.string({
description: 'registry address',
}),
token: core_1.Flags.string({
description: 'api token',
}),
require: core_1.Flags.string({
description: 'Loads specific require.extensions before running the codegen and reading the configuration',
default: [],
multiple: true,
}),
};
OperationsPublish.args = [
{
name: 'file',
required: true,
description: 'Glob pattern to find the operations',
hidden: false,
},
];
exports.default = OperationsPublish;
//# sourceMappingURL=publish.js.map