@graphql-inspector/action
Version:
GraphQL Inspector functionality for GitHub Actions
47 lines (46 loc) • 1.33 kB
JavaScript
// Right now everything is hardcoded for better UX but this may change in future.
// It's just easier to leave it this way
Object.defineProperty(exports, "__esModule", { value: true });
exports.availableLoaders = exports.availableCommands = void 0;
exports.useConfig = useConfig;
exports.availableCommands = [
'coverage',
'diff',
'docs',
'introspect',
'serve',
'similar',
'validate',
];
exports.availableLoaders = ['code', 'git', 'github', 'graphql', 'json', 'url'];
async function useConfig() {
return {
loaders: ensureList(discoverLoaders(exports.availableLoaders), 'loaders'),
commands: ensureList(discoverCommands(exports.availableCommands), 'commands'),
};
}
function moduleExists(name) {
try {
require.resolve(name);
return true;
}
catch (error) {
return false;
}
}
function discoverLoaders(loaders) {
return loaders.filter(name => moduleExists(`@graphql-inspector/${name}-loader`));
}
function discoverCommands(commands) {
return commands.filter(name => moduleExists(`@graphql-inspector/${name}-command`));
}
function ensureList(list, path) {
if (!list) {
return [];
}
if (Array.isArray(list)) {
return list;
}
throw new Error(`Value of ${path} expected to be a list`);
}
;