Socket
Socket
Sign inDemoInstall

@graphql-inspector/commands

Package Overview
Dependencies
Maintainers
1
Versions
418
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-inspector/commands - npm Package Compare versions

Comparing version 0.0.0-canary.57e2caa to 0.0.0-canary.58ffd99

116

index.cjs.js

@@ -10,117 +10,4 @@ 'use strict';

const yargs = _interopDefault(require('yargs'));
const fs = require('fs');
const yamljs = require('yamljs');
const searchPlaces = [
`graphql.config.js`,
'graphql.config.json',
'graphql.config.yaml',
'graphql.config.yml',
'.graphqlrc',
'.graphqlrc.js',
'.graphqlrc.json',
'.graphqlrc.yml',
'.graphqlrc.yaml',
];
const legacySearchPlaces = [
'.graphqlconfig',
'.graphqlconfig.json',
'.graphqlconfig.yaml',
'.graphqlconfig.yml',
];
const pickPointers = (args, required) => tslib.__awaiter(void 0, void 0, void 0, function* () {
let schema;
let documents;
if (args.config) {
const config = yield useGraphQLConfig();
schema = config.schema;
documents = config.documents;
}
else {
schema = args.schema;
documents = args.documents;
}
if (required.documents || required.schema) {
const errors = [];
if (required.schema && !schema) {
errors.push(`Schema pointer is missing`);
}
if (required.documents && !documents) {
errors.push(`Documents pointer is missing`);
}
if (errors.length) {
throw new Error(errors.join('\n'));
}
}
return {
schema,
documents,
};
});
function useGraphQLConfig() {
return tslib.__awaiter(this, void 0, void 0, function* () {
const found = yield firstExisting(searchPlaces);
if (found) {
return parse(found);
}
const foundLegacy = yield firstExisting(legacySearchPlaces);
if (foundLegacy) {
return parse(foundLegacy);
}
throw new Error(`Couldn't find a GraphQL Config`);
});
}
function firstExisting(places) {
return tslib.__awaiter(this, void 0, void 0, function* () {
const statuses = yield Promise.all(places.map((place) => path.resolve(process.cwd(), place)).map(exists));
return places.find((_, i) => statuses[i] === true);
});
}
function parse(path$1) {
return tslib.__awaiter(this, void 0, void 0, function* () {
const normalizedPath = path.resolve(process.cwd(), path$1.toLowerCase());
if (normalizedPath.endsWith('.js')) {
const mod = require(normalizedPath);
return mod.default || mod;
}
const content = yield read(path$1);
if (normalizedPath.endsWith('.yml') || normalizedPath.endsWith('.yaml')) {
return yamljs.parse(content);
}
if (normalizedPath.endsWith('.json')) {
return JSON.parse(content);
}
try {
return yamljs.parse(content);
}
catch (error) { }
try {
return JSON.parse(content);
}
catch (error) { }
throw new Error(`Failed to parse: ${path$1}`);
});
}
function read(path) {
return new Promise((resolve, reject) => {
fs.readFile(path, 'utf-8', (error, data) => {
if (error) {
reject(error);
}
else {
resolve(data);
}
});
});
}
function exists(path) {
return new Promise((resolve) => {
fs.stat(path, (error) => {
resolve(error ? false : true);
});
});
}
function useCommands(input) {
const api = Object.assign(Object.assign({}, input), { pickPointers });
function useCommands(api) {
return api.config.commands.map((name) => loadCommand(name)(api));

@@ -170,4 +57,3 @@ }

exports.parseGlobalArgs = parseGlobalArgs;
exports.pickPointers = pickPointers;
exports.useCommands = useCommands;
//# sourceMappingURL=index.cjs.js.map

12

index.d.ts
import { InspectorConfig } from '@graphql-inspector/config';
import { Loaders } from '@graphql-inspector/loaders';
import { CommandModule } from 'yargs';
import { pickPointers, PickPointers } from './graphql-config';
export { CommandModule as Command, PickPointers, pickPointers };
import { CommandModule as Command } from 'yargs';
export { Command };
export interface UseCommandsAPI {
config: InspectorConfig;
loaders: Loaders;
pickPointers: PickPointers;
}
export declare type CommandFactory<T = {}, U = {}> = (api: UseCommandsAPI) => CommandModule<T, U>;
export declare function useCommands(input: Omit<UseCommandsAPI, 'pickPointers'>): CommandModule[];
export declare type CommandFactory<T = {}, U = {}> = (api: Required<UseCommandsAPI>) => Command<T, U>;
export declare function useCommands(api: UseCommandsAPI): Command[];
export declare function createCommand<T = {}, U = {}>(factory: CommandFactory<T, U>): CommandFactory<T, U>;

@@ -24,2 +22,2 @@ export declare function ensureAbsolute(filepath: string, basepath?: string): string;

};
export declare function mockCommand(mod: CommandModule, cmd: string): Promise<string>;
export declare function mockCommand(mod: Command, cmd: string): Promise<string>;
import { __awaiter } from 'tslib';
import { resolve, isAbsolute } from 'path';
import { isAbsolute, resolve } from 'path';
import yargs from 'yargs';
import { readFile, stat } from 'fs';
import { parse as parse$1 } from 'yamljs';
const searchPlaces = [
`graphql.config.js`,
'graphql.config.json',
'graphql.config.yaml',
'graphql.config.yml',
'.graphqlrc',
'.graphqlrc.js',
'.graphqlrc.json',
'.graphqlrc.yml',
'.graphqlrc.yaml',
];
const legacySearchPlaces = [
'.graphqlconfig',
'.graphqlconfig.json',
'.graphqlconfig.yaml',
'.graphqlconfig.yml',
];
const pickPointers = (args, required) => __awaiter(void 0, void 0, void 0, function* () {
let schema;
let documents;
if (args.config) {
const config = yield useGraphQLConfig();
schema = config.schema;
documents = config.documents;
}
else {
schema = args.schema;
documents = args.documents;
}
if (required.documents || required.schema) {
const errors = [];
if (required.schema && !schema) {
errors.push(`Schema pointer is missing`);
}
if (required.documents && !documents) {
errors.push(`Documents pointer is missing`);
}
if (errors.length) {
throw new Error(errors.join('\n'));
}
}
return {
schema,
documents,
};
});
function useGraphQLConfig() {
return __awaiter(this, void 0, void 0, function* () {
const found = yield firstExisting(searchPlaces);
if (found) {
return parse(found);
}
const foundLegacy = yield firstExisting(legacySearchPlaces);
if (foundLegacy) {
return parse(foundLegacy);
}
throw new Error(`Couldn't find a GraphQL Config`);
});
}
function firstExisting(places) {
return __awaiter(this, void 0, void 0, function* () {
const statuses = yield Promise.all(places.map((place) => resolve(process.cwd(), place)).map(exists));
return places.find((_, i) => statuses[i] === true);
});
}
function parse(path) {
return __awaiter(this, void 0, void 0, function* () {
const normalizedPath = resolve(process.cwd(), path.toLowerCase());
if (normalizedPath.endsWith('.js')) {
const mod = require(normalizedPath);
return mod.default || mod;
}
const content = yield read(path);
if (normalizedPath.endsWith('.yml') || normalizedPath.endsWith('.yaml')) {
return parse$1(content);
}
if (normalizedPath.endsWith('.json')) {
return JSON.parse(content);
}
try {
return parse$1(content);
}
catch (error) { }
try {
return JSON.parse(content);
}
catch (error) { }
throw new Error(`Failed to parse: ${path}`);
});
}
function read(path) {
return new Promise((resolve, reject) => {
readFile(path, 'utf-8', (error, data) => {
if (error) {
reject(error);
}
else {
resolve(data);
}
});
});
}
function exists(path) {
return new Promise((resolve) => {
stat(path, (error) => {
resolve(error ? false : true);
});
});
}
function useCommands(input) {
const api = Object.assign(Object.assign({}, input), { pickPointers });
function useCommands(api) {
return api.config.commands.map((name) => loadCommand(name)(api));

@@ -159,3 +46,3 @@ }

export { createCommand, ensureAbsolute, mockCommand, parseGlobalArgs, pickPointers, useCommands };
export { createCommand, ensureAbsolute, mockCommand, parseGlobalArgs, useCommands };
//# sourceMappingURL=index.esm.js.map
{
"name": "@graphql-inspector/commands",
"version": "0.0.0-canary.57e2caa",
"version": "0.0.0-canary.58ffd99",
"description": "Plugin system for commands in GraphQL Inspector",
"sideEffects": false,
"peerDependencies": {
"@graphql-inspector/config": "0.0.0-canary.57e2caa",
"@graphql-inspector/loaders": "0.0.0-canary.57e2caa",
"@graphql-inspector/config": "0.0.0-canary.58ffd99",
"@graphql-inspector/loaders": "0.0.0-canary.58ffd99",
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0",

@@ -12,4 +13,3 @@ "yargs": "15.3.1"

"dependencies": {
"tslib": "^1.11.1",
"yamljs": "0.3.0"
"tslib": "^2.0.0"
},

@@ -16,0 +16,0 @@ "repository": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc