New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-tool-utilities

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-tool-utilities - npm Package Compare versions

Comparing version 0.8.0-beta.1 to 0.8.0-beta.2

index.d.ts

2

augmentations.d.ts
declare module 'graphql-config/lib/GraphQLProjectConfig' {
interface GraphQLProjectConfig {
resolvePathRelativeToConfig(relativePath: string): string;
resolveProjectName(defaultName?: string): string;
resolveSchemaPath(): string;
}
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const GraphQLProjectConfig_1 = require("graphql-config/lib/GraphQLProjectConfig");
// temporary augmentation until `graphql-config` supports this new function
// see: https://github.com/prisma/graphql-config/pull/113
function resolvePathRelativeToConfig(relativePath) {
// this is just an alias to resolveConfigPath with a more meaningful name
return this.resolveConfigPath(relativePath);
}
function resolveProjectName(defaultName = 'GraphQL') {
return this.projectName || defaultName;
}
function resolveSchemaPath() {
// schemaPath is nullable in graphq-config even though it cannot actually be
// omitted. This function simplifies access ot the schemaPath without
// requiring a type guard.
if (!this.schemaPath) {
// this case should never happen with a properly formatted config file.
// graphql-config currently does not perform any validation so it's possible
// for a mal-formed schema to be loaded at runtime.
throw new Error(`Missing GraphQL schemaPath for project '${this.resolveProjectName()}'`);
}
// resolve fully qualified schemaPath
const schemaPath = this.resolveConfigPath(this.schemaPath);
if (!fs_1.existsSync(schemaPath)) {
const forProject = this.projectName
? ` for project '${this.projectName}'`
: '';
throw new Error([
`Schema not found${forProject}.`,
`Expected to find the schema at '${schemaPath}' but the path does not exist.`,
`Check '${this.configPath}' and verify that schemaPath is configured correctly${forProject}.`,
].join(' '));
}
return schemaPath;
}
GraphQLProjectConfig_1.GraphQLProjectConfig.prototype.resolvePathRelativeToConfig = resolvePathRelativeToConfig;
GraphQLProjectConfig_1.GraphQLProjectConfig.prototype.resolveProjectName = resolveProjectName;
GraphQLProjectConfig_1.GraphQLProjectConfig.prototype.resolveSchemaPath = resolveSchemaPath;

@@ -0,1 +1,2 @@

import {existsSync} from 'fs';
import {GraphQLProjectConfig} from 'graphql-config/lib/GraphQLProjectConfig';

@@ -5,6 +6,18 @@

interface GraphQLProjectConfig {
resolvePathRelativeToConfig(relativePath: string): string;
resolveProjectName(defaultName?: string): string;
resolveSchemaPath(): string;
}
}
// temporary augmentation until `graphql-config` supports this new function
// see: https://github.com/prisma/graphql-config/pull/113
function resolvePathRelativeToConfig(
this: GraphQLProjectConfig,
relativePath: string,
) {
// this is just an alias to resolveConfigPath with a more meaningful name
return this.resolveConfigPath(relativePath);
}
function resolveProjectName(

@@ -17,2 +30,38 @@ this: GraphQLProjectConfig,

function resolveSchemaPath(this: GraphQLProjectConfig) {
// schemaPath is nullable in graphq-config even though it cannot actually be
// omitted. This function simplifies access ot the schemaPath without
// requiring a type guard.
if (!this.schemaPath) {
// this case should never happen with a properly formatted config file.
// graphql-config currently does not perform any validation so it's possible
// for a mal-formed schema to be loaded at runtime.
throw new Error(
`Missing GraphQL schemaPath for project '${this.resolveProjectName()}'`,
);
}
// resolve fully qualified schemaPath
const schemaPath = this.resolveConfigPath(this.schemaPath);
if (!existsSync(schemaPath)) {
const forProject = this.projectName
? ` for project '${this.projectName}'`
: '';
throw new Error(
[
`Schema not found${forProject}.`,
`Expected to find the schema at '${schemaPath}' but the path does not exist.`,
`Check '${
this.configPath
}' and verify that schemaPath is configured correctly${forProject}.`,
].join(' '),
);
}
return schemaPath;
}
GraphQLProjectConfig.prototype.resolvePathRelativeToConfig = resolvePathRelativeToConfig;
GraphQLProjectConfig.prototype.resolveProjectName = resolveProjectName;
GraphQLProjectConfig.prototype.resolveSchemaPath = resolveSchemaPath;

2

config.d.ts

@@ -5,3 +5,3 @@ import { GraphQLConfig, GraphQLProjectConfig } from 'graphql-config';

export declare function getGraphQLSchemaPaths(config: GraphQLConfig): string[];
export declare function getGraphQLProjectIncludedFilePaths(projectConfig: GraphQLProjectConfig): Promise<string[]>;
export declare function getGraphQLProjectForSchemaPath(config: GraphQLConfig, schemaPath: string): GraphQLProjectConfig;
export declare function getGraphQLFilePath(config: GraphQLConfig | GraphQLProjectConfig, filePath: string): string;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const glob_1 = __importDefault(require("glob"));
const util_1 = require("util");
require("./augmentations");

@@ -21,11 +33,17 @@ function getGraphQLProjects(config) {

function getGraphQLSchemaPaths(config) {
return getGraphQLProjects(config).reduce((schemas, { schemaPath }) => {
return schemaPath
? schemas.concat(getGraphQLFilePath(config, schemaPath))
: schemas;
return getGraphQLProjects(config).reduce((schemas, project) => {
return schemas.concat(project.resolveSchemaPath());
}, []);
}
exports.getGraphQLSchemaPaths = getGraphQLSchemaPaths;
function getGraphQLProjectIncludedFilePaths(projectConfig) {
return __awaiter(this, void 0, void 0, function* () {
return (yield Promise.all(projectConfig.includes.map((include) => util_1.promisify(glob_1.default)(projectConfig.resolvePathRelativeToConfig(include), {
ignore: projectConfig.excludes.map((exclude) => projectConfig.resolvePathRelativeToConfig(exclude)),
})))).flatMap((filePaths) => filePaths);
});
}
exports.getGraphQLProjectIncludedFilePaths = getGraphQLProjectIncludedFilePaths;
function getGraphQLProjectForSchemaPath(config, schemaPath) {
const project = Object.values(config.getProjects() || {})
const project = getGraphQLProjects(config)
.filter((project) => project.schemaPath === schemaPath)

@@ -39,5 +57,1 @@ .shift() || config.getProjectConfig();

exports.getGraphQLProjectForSchemaPath = getGraphQLProjectForSchemaPath;
function getGraphQLFilePath(config, filePath) {
return path_1.isAbsolute(filePath) ? filePath : path_1.resolve(config.configDir, filePath);
}
exports.getGraphQLFilePath = getGraphQLFilePath;

@@ -0,3 +1,4 @@

import glob from 'glob';
import {GraphQLConfig, GraphQLProjectConfig} from 'graphql-config';
import {isAbsolute, resolve} from 'path';
import {promisify} from 'util';

@@ -26,12 +27,21 @@ import './augmentations';

export function getGraphQLSchemaPaths(config: GraphQLConfig) {
return getGraphQLProjects(config).reduce<string[]>(
(schemas, {schemaPath}) => {
return schemaPath
? schemas.concat(getGraphQLFilePath(config, schemaPath))
: schemas;
},
[],
);
return getGraphQLProjects(config).reduce<string[]>((schemas, project) => {
return schemas.concat(project.resolveSchemaPath());
}, []);
}
export async function getGraphQLProjectIncludedFilePaths(
projectConfig: GraphQLProjectConfig,
) {
return (await Promise.all(
projectConfig.includes.map((include) =>
promisify(glob)(projectConfig.resolvePathRelativeToConfig(include), {
ignore: projectConfig.excludes.map((exclude) =>
projectConfig.resolvePathRelativeToConfig(exclude),
),
}),
),
)).flatMap((filePaths) => filePaths);
}
export function getGraphQLProjectForSchemaPath(

@@ -42,3 +52,3 @@ config: GraphQLConfig,

const project =
Object.values(config.getProjects() || {})
getGraphQLProjects(config)
.filter((project) => project.schemaPath === schemaPath)

@@ -55,8 +65,1 @@ .shift() || config.getProjectConfig();

}
export function getGraphQLFilePath(
config: GraphQLConfig | GraphQLProjectConfig,
filePath: string,
) {
return isAbsolute(filePath) ? filePath : resolve(config.configDir, filePath);
}
{
"name": "graphql-tool-utilities",
"description": "Common utilities for GraphQL developer tools",
"version": "0.8.0-beta.1",
"version": "0.8.0-beta.2",
"license": "MIT",

@@ -33,7 +33,7 @@ "publishConfig": {

"@types/graphql": "^0.13.0",
"apollo-codegen-core": "0.20.1",
"apollo-codegen-core": "0.28.1",
"core-js": "^2.4.1",
"graphql": "0.13.2",
"graphql-config": "2.1.0"
"graphql-config": "2.1.1"
}
}
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