sanity
Version:
Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches
68 lines (67 loc) • 2.45 kB
JavaScript
import { hideBin } from "yargs/helpers";
import yargs from "yargs/yargs";
import { getGraphQLAPIs } from "./getGraphQLAPIs.js";
function parseCliFlags(args) {
return yargs(hideBin(args.argv || process.argv).slice(2)).option("api", {
type: "string"
}).option("project", {
type: "string"
}).option("dataset", {
type: "string"
}).option("tag", {
type: "string",
default: "default"
}).option("force", {
type: "boolean"
}).argv;
}
async function deleteGraphQLApi(args, context) {
const flags = await parseCliFlags(args), {
apiClient,
output,
prompt
} = context;
let projectId = flags.project, dataset = flags.dataset, tag = flags.tag;
if (flags.api) {
const apiDef = (await getGraphQLAPIs(context)).find((def) => def.id === flags.api);
if (!apiDef)
throw new Error(`GraphQL API "${flags.api}" not found`);
projectId ? output.warn(`Both --api and --project specified, using --project ${projectId}`) : projectId = apiDef.projectId, dataset ? output.warn(`Both --api and --dataset specified, using --dataset ${dataset}`) : dataset = apiDef.dataset, tag && apiDef.tag ? output.warn(`Both --api and --tag specified, using --tag ${tag}`) : tag = apiDef.tag || "default";
}
let client;
!projectId || !dataset ? (client = apiClient({
requireUser: !0,
requireProject: !0
}).config({
apiVersion: "2023-08-01"
}), projectId = projectId || client.config().projectId, dataset = dataset || client.config().dataset) : client = apiClient({
requireProject: !1,
requireUser: !0
}).config({
projectId,
dataset
});
const confirmMessage = tag === "default" ? `Are you absolutely sure you want to delete the current GraphQL API connected to the "${dataset}" dataset in project ${projectId}?` : `Are you absolutely sure you want to delete the GraphQL API connected to the "${dataset}" dataset in project ${projectId}, tagged "${tag}"?`;
if (flags.force || await prompt.single({
type: "confirm",
message: confirmMessage,
default: !1
})) {
projectId !== client.config().projectId && (client = client.clone().config({
projectId
}));
try {
await client.request({
url: `/apis/graphql/${dataset}/${tag}`,
method: "DELETE"
});
} catch (err) {
throw err;
}
output.print("GraphQL API deleted");
}
}
export {
deleteGraphQLApi as default
};
//# sourceMappingURL=deleteApiAction.js.map