UNPKG

@graphql-hive/cli

Version:

A CLI util to manage and control your GraphQL Hive

67 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadSchemaFromGitHistory = loadSchemaFromGitHistory; const node_child_process_1 = require("node:child_process"); function isGlobPath(path) { const globPattern = /[*?{}\[\]()]/; return globPattern.test(path); } const filePathPattern = 'file://'; function parseSingleLocalFilePath(schemaPointer) { if (schemaPointer.includes('://') && !schemaPointer.startsWith(filePathPattern)) { return { status: 'error', error: { type: 'path', message: 'URL is not a local path.', }, }; } if (isGlobPath(schemaPointer)) { return { status: 'error', error: { type: 'path', message: 'Path is a glob pattern.', }, }; } return { status: 'ok', path: schemaPointer.startsWith(filePathPattern) ? schemaPointer.substring(0, filePathPattern.length) : schemaPointer, }; } const buildShowGitFileCommand = (commit, path) => `git show ${commit}:${path}`; function loadGitFile(commit, path) { try { const sdl = (0, node_child_process_1.execSync)(buildShowGitFileCommand(commit, path), { cwd: process.cwd() }).toString(); return { status: 'ok', sdl, }; } catch (error) { if (error instanceof Error) { return { status: 'error', error: { type: 'git', message: 'Failed to load schema SDL.\n' + error.message, path, }, }; } throw error; } } function loadSchemaFromGitHistory(schemaPointer, commit) { const pathResult = parseSingleLocalFilePath(schemaPointer); if (pathResult.error) { return pathResult; } const fileResult = loadGitFile(commit, pathResult.path); return fileResult; } //# sourceMappingURL=git-schema-loader.js.map