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

graphql-config

Package Overview
Dependencies
Maintainers
10
Versions
343
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-config - npm Package Compare versions

Comparing version 3.0.0-alpha.15 to 3.0.0-alpha.16

9

extension.d.ts

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

import { SchemaPointerSingle, DocumentPointerSingle } from '@graphql-toolkit/common';
import { LoadersRegistry } from './loaders';

@@ -7,4 +6,4 @@ export declare type GraphQLExtensionDeclaration = (api: ExtensionAPI) => GraphQLConfigExtension;

loaders: {
schema: Pick<LoadersRegistry<SchemaPointerSingle>, 'register'>;
documents: Pick<LoadersRegistry<DocumentPointerSingle>, 'register'>;
schema: Pick<LoadersRegistry, 'register'>;
documents: Pick<LoadersRegistry, 'register'>;
};

@@ -18,4 +17,4 @@ }

readonly loaders: {
schema: LoadersRegistry<SchemaPointerSingle>;
documents: LoadersRegistry<DocumentPointerSingle>;
schema: LoadersRegistry;
documents: LoadersRegistry;
};

@@ -22,0 +21,0 @@ constructor({ cwd }: {

@@ -7,21 +7,2 @@ 'use strict';

function _interopNamespace(e) {
if (e && e.__esModule) { return e; } else {
var n = {};
if (e) {
Object.keys(e).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
});
}
n['default'] = e;
return n;
}
}
const path = require('path');

@@ -31,2 +12,3 @@ const graphql = require('graphql');

const minimatch = _interopDefault(require('minimatch'));
const core = require('@graphql-toolkit/core');
const cosmiconfig = _interopDefault(require('cosmiconfig'));

@@ -201,2 +183,131 @@ const graphqlFileLoader = require('@graphql-toolkit/graphql-file-loader');

var GraphQLProjectConfig = /** @class */ (function () {
function GraphQLProjectConfig(_a) {
var filepath = _a.filepath, name = _a.name, config = _a.config, extensionsRegistry = _a.extensionsRegistry;
this.filepath = filepath;
this.dirpath = path.dirname(filepath);
this.name = name;
this.extensions = config.extensions || {};
this.schema = config.schema;
this.documents = config.documents;
this.include = config.include;
this.exclude = config.exclude;
this._extensionsRegistry = extensionsRegistry;
}
GraphQLProjectConfig.prototype.hasExtension = function (name) {
return !!this.extensions[name];
};
GraphQLProjectConfig.prototype.extension = function (name) {
var extension = this._extensionsRegistry.get(name);
if (!extension) {
throw new ExtensionMissingError("Project " + this.name + " is missing " + name + " extension");
}
return __assign(__assign({}, this.extensions[name]), { schema: this.schema, documents: this.documents, include: this.include, exclude: this.exclude });
};
GraphQLProjectConfig.prototype.getSchema = function (out) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.loadSchema(this.schema, out)];
});
});
};
GraphQLProjectConfig.prototype.getDocuments = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!this.documents) {
return [2 /*return*/, []];
}
return [2 /*return*/, this.loadDocuments(this.documents)];
});
});
};
GraphQLProjectConfig.prototype.loadSchema = function (pointer, out) {
return __awaiter(this, void 0, void 0, function () {
var sources, mergedTypedefs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
out = out || 'GraphQLSchema';
if (!(out === 'GraphQLSchema')) return [3 /*break*/, 1];
return [2 /*return*/, this._extensionsRegistry.loaders.schema.loadSchema(pointer)];
case 1: return [4 /*yield*/, this._extensionsRegistry.loaders.schema.loadTypeDefs(pointer, {
filterKinds: core.OPERATION_KINDS,
})];
case 2:
sources = _a.sent();
mergedTypedefs = schemaMerging.mergeTypeDefs(sources.map(function (s) { return s.document; }));
if (typeof mergedTypedefs === 'string') {
if (out === 'string') {
return [2 /*return*/, mergedTypedefs];
}
else if (out === 'DocumentNode') {
return [2 /*return*/, graphql.parse(mergedTypedefs)];
}
}
else if ('kind' in mergedTypedefs) {
if (out === 'DocumentNode') {
return [2 /*return*/, mergedTypedefs];
}
else if (out === 'string') {
return [2 /*return*/, graphql.print(mergedTypedefs)];
}
}
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
GraphQLProjectConfig.prototype.loadDocuments = function (pointer) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!pointer) {
return [2 /*return*/, []];
}
return [2 /*return*/, this._extensionsRegistry.loaders.documents.loadDocuments(pointer)];
});
});
};
GraphQLProjectConfig.prototype.match = function (filepath) {
var _this = this;
var isSchemaOrDocument = [this.schema, this.documents].some(function (pointer) {
return match(filepath, _this.dirpath, pointer);
});
if (isSchemaOrDocument) {
return true;
}
var isExcluded = this.exclude
? match(filepath, this.dirpath, this.exclude)
: false;
if (isExcluded) {
return false;
}
var isIncluded = this.include
? match(filepath, this.dirpath, this.include)
: false;
if (isIncluded) {
return true;
}
return false;
};
return GraphQLProjectConfig;
}());
// XXX: it works but uses nodejs - expose normalization of file and dir paths in config
function match(filepath, dirpath, pointer) {
if (!pointer) {
return false;
}
if (Array.isArray(pointer)) {
return pointer.some(function (p) { return match(filepath, dirpath, p); });
}
if (typeof pointer === 'string') {
var normalizedFilepath = path.normalize(path.isAbsolute(filepath) ? path.relative(dirpath, filepath) : filepath);
return minimatch(normalizedFilepath, path.normalize(pointer), { dot: true });
}
if (typeof pointer === 'object') {
return match(filepath, dirpath, Object.keys(pointer)[0]);
}
return false;
}
var cwd = typeof process !== 'undefined' ? process.cwd() : undefined;

@@ -309,224 +420,35 @@ function isMultipleProjectConfig(config) {

}
function flatten(arr) {
var _a;
return (_a = Array.prototype).concat.apply(_a, arr);
}
function pick(key, items) {
return items.map(function (item) { return item[key]; });
}
var GraphQLProjectConfig = /** @class */ (function () {
function GraphQLProjectConfig(_a) {
var filepath = _a.filepath, name = _a.name, config = _a.config, extensionsRegistry = _a.extensionsRegistry;
this.filepath = filepath;
this.dirpath = path.dirname(filepath);
this.name = name;
this.extensions = config.extensions || {};
this.schema = config.schema;
this.documents = config.documents;
this.include = config.include;
this.exclude = config.exclude;
this._extensionsRegistry = extensionsRegistry;
var LoadersRegistry = /** @class */ (function () {
function LoadersRegistry(_a) {
var cwd = _a.cwd;
this._loaders = [];
this.cwd = cwd;
}
GraphQLProjectConfig.prototype.hasExtension = function (name) {
return !!this.extensions[name];
};
GraphQLProjectConfig.prototype.extension = function (name) {
var extension = this._extensionsRegistry.get(name);
if (!extension) {
throw new ExtensionMissingError("Project " + this.name + " is missing " + name + " extension");
LoadersRegistry.prototype.register = function (loader) {
if (!this._loaders.some(function (l) { return l.loaderId() === loader.loaderId(); })) {
this._loaders.push(loader);
}
return __assign(__assign({}, this.extensions[name]), { schema: this.schema, documents: this.documents, include: this.include, exclude: this.exclude });
};
GraphQLProjectConfig.prototype.getSchema = function (out) {
LoadersRegistry.prototype.loadTypeDefs = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.loadSchema(this.schema, out)];
return [2 /*return*/, core.loadTypedefs(pointer, __assign({ loaders: this._loaders, cwd: this.cwd }, options))];
});
});
};
GraphQLProjectConfig.prototype.getDocuments = function () {
LoadersRegistry.prototype.loadDocuments = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!this.documents) {
return [2 /*return*/, []];
}
return [2 /*return*/, this.loadDocuments(this.documents)];
return [2 /*return*/, core.loadDocuments(pointer, __assign({ loaders: this._loaders, cwd: this.cwd }, options))];
});
});
};
GraphQLProjectConfig.prototype.loadSchema = function (pointer, out) {
LoadersRegistry.prototype.loadSchema = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
var schema, schemas, _a, _b, _c;
var _this = this;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!Array.isArray(pointer)) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.all(pointer.map(function (_pointer) {
return _this._extensionsRegistry.loaders.schema.load(_pointer);
}))];
case 1:
schemas = _d.sent();
schema = schemaMerging.mergeTypeDefs(flatten(schemas).map(function (s) { return s.document; }));
return [3 /*break*/, 4];
case 2:
_a = schemaMerging.mergeTypeDefs;
_b = pick;
_c = ['document'];
return [4 /*yield*/, this._extensionsRegistry.loaders.schema.load(pointer)];
case 3:
schema = _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()]))]);
_d.label = 4;
case 4:
if (out === 'DocumentNode') {
return [2 /*return*/, schema];
}
return [2 /*return*/, graphql.buildASTSchema(schema)];
}
return __generator(this, function (_a) {
return [2 /*return*/, core.loadSchema(pointer, __assign({ loaders: this._loaders, cwd: this.cwd }, options))];
});
});
};
GraphQLProjectConfig.prototype.loadDocuments = function (pointer) {
return __awaiter(this, void 0, void 0, function () {
var _a;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!pointer) {
return [2 /*return*/, []];
}
if (!Array.isArray(pointer)) return [3 /*break*/, 2];
_a = flatten;
return [4 /*yield*/, Promise.all(pointer.map(function (_pointer) {
return _this._extensionsRegistry.loaders.documents.load(_pointer);
}))];
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
case 2: return [2 /*return*/, this._extensionsRegistry.loaders.documents.load(pointer)];
}
});
});
};
GraphQLProjectConfig.prototype.match = function (filepath) {
var _this = this;
var isSchemaOrDocument = [this.schema, this.documents].some(function (pointer) {
return match(filepath, _this.dirpath, pointer);
});
if (isSchemaOrDocument) {
return true;
}
var isExcluded = this.exclude
? match(filepath, this.dirpath, this.exclude)
: false;
if (isExcluded) {
return false;
}
var isIncluded = this.include
? match(filepath, this.dirpath, this.include)
: false;
if (isIncluded) {
return true;
}
return false;
};
return GraphQLProjectConfig;
}());
// XXX: it works but uses nodejs - expose normalization of file and dir paths in config
function match(filepath, dirpath, pointer) {
if (!pointer) {
return false;
}
if (Array.isArray(pointer)) {
return pointer.some(function (p) { return match(filepath, dirpath, p); });
}
if (typeof pointer === 'string') {
var normalizedFilepath = path.normalize(path.isAbsolute(filepath) ? path.relative(dirpath, filepath) : filepath);
return minimatch(normalizedFilepath, path.normalize(pointer), { dot: true });
}
if (typeof pointer === 'object') {
return match(filepath, dirpath, Object.keys(pointer)[0]);
}
return false;
}
function isGlob(pointer) {
return typeof pointer === 'string' && pointer.includes('*');
}
function isPointerWithConfiguration(pointer) {
var isObject = typeof pointer === 'object';
var hasOneKey = Object.keys(pointer).length === 1;
var key = Object.keys(pointer)[0];
var hasConfiguration = typeof pointer[key] === 'object';
return isObject && hasOneKey && hasConfiguration;
}
function isSourceArray(sources) {
return Array.isArray(sources);
}
var LoadersRegistry = /** @class */ (function () {
function LoadersRegistry(_a) {
var cwd = _a.cwd;
this._loaders = [];
this.cwd = cwd;
}
LoadersRegistry.prototype.register = function (loader) {
if (!this._loaders.some(function (l) { return l.loaderId() === loader.loaderId(); })) {
this._loaders.push(loader);
}
};
LoadersRegistry.prototype.load = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
var globby, filepaths, results, key, _i, _a, loader, result;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!options) {
options = {};
}
options.cwd = this.cwd;
if (!isGlob(pointer)) return [3 /*break*/, 4];
return [4 /*yield*/, new Promise(function (resolve) { resolve(_interopNamespace(require('globby'))); })];
case 1:
globby = (_b.sent()).default;
return [4 /*yield*/, globby(pointer, {
cwd: this.cwd,
})];
case 2:
filepaths = _b.sent();
return [4 /*yield*/, Promise.all(filepaths.map(function (filepath) { return _this.load(filepath, options); }))];
case 3:
results = _b.sent();
return [2 /*return*/, flatten(results.filter(isSourceArray))];
case 4:
if (isPointerWithConfiguration(pointer)) {
key = Object.keys(pointer)[0];
return [2 /*return*/, this.load(key, pointer[key])];
}
if (this._loaders.length === 0) {
throw new LoadersMissingError("Loaders are missing");
}
_i = 0, _a = this._loaders;
_b.label = 5;
case 5:
if (!(_i < _a.length)) return [3 /*break*/, 9];
loader = _a[_i];
return [4 /*yield*/, loader.canLoad(pointer, options)];
case 6:
if (!_b.sent()) return [3 /*break*/, 8];
return [4 /*yield*/, loader.load(pointer, options)];
case 7:
result = _b.sent();
if (result) {
return [2 /*return*/, [result]];
}
_b.label = 8;
case 8:
_i++;
return [3 /*break*/, 5];
case 9: throw new LoaderNoResultError("None of provided loaders could resolve: " + pointer);
}
});
});
};
return LoadersRegistry;

@@ -533,0 +455,0 @@ }());

import { normalize, isAbsolute, relative, dirname } from 'path';
import { buildASTSchema } from 'graphql';
import { parse, print } from 'graphql';
import { mergeTypeDefs } from '@graphql-toolkit/schema-merging';
import minimatch from 'minimatch';
import { OPERATION_KINDS, loadTypedefs, loadDocuments, loadSchema } from '@graphql-toolkit/core';
import cosmiconfig from 'cosmiconfig';

@@ -174,2 +175,131 @@ import { GraphQLFileLoader } from '@graphql-toolkit/graphql-file-loader';

var GraphQLProjectConfig = /** @class */ (function () {
function GraphQLProjectConfig(_a) {
var filepath = _a.filepath, name = _a.name, config = _a.config, extensionsRegistry = _a.extensionsRegistry;
this.filepath = filepath;
this.dirpath = dirname(filepath);
this.name = name;
this.extensions = config.extensions || {};
this.schema = config.schema;
this.documents = config.documents;
this.include = config.include;
this.exclude = config.exclude;
this._extensionsRegistry = extensionsRegistry;
}
GraphQLProjectConfig.prototype.hasExtension = function (name) {
return !!this.extensions[name];
};
GraphQLProjectConfig.prototype.extension = function (name) {
var extension = this._extensionsRegistry.get(name);
if (!extension) {
throw new ExtensionMissingError("Project " + this.name + " is missing " + name + " extension");
}
return __assign(__assign({}, this.extensions[name]), { schema: this.schema, documents: this.documents, include: this.include, exclude: this.exclude });
};
GraphQLProjectConfig.prototype.getSchema = function (out) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.loadSchema(this.schema, out)];
});
});
};
GraphQLProjectConfig.prototype.getDocuments = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!this.documents) {
return [2 /*return*/, []];
}
return [2 /*return*/, this.loadDocuments(this.documents)];
});
});
};
GraphQLProjectConfig.prototype.loadSchema = function (pointer, out) {
return __awaiter(this, void 0, void 0, function () {
var sources, mergedTypedefs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
out = out || 'GraphQLSchema';
if (!(out === 'GraphQLSchema')) return [3 /*break*/, 1];
return [2 /*return*/, this._extensionsRegistry.loaders.schema.loadSchema(pointer)];
case 1: return [4 /*yield*/, this._extensionsRegistry.loaders.schema.loadTypeDefs(pointer, {
filterKinds: OPERATION_KINDS,
})];
case 2:
sources = _a.sent();
mergedTypedefs = mergeTypeDefs(sources.map(function (s) { return s.document; }));
if (typeof mergedTypedefs === 'string') {
if (out === 'string') {
return [2 /*return*/, mergedTypedefs];
}
else if (out === 'DocumentNode') {
return [2 /*return*/, parse(mergedTypedefs)];
}
}
else if ('kind' in mergedTypedefs) {
if (out === 'DocumentNode') {
return [2 /*return*/, mergedTypedefs];
}
else if (out === 'string') {
return [2 /*return*/, print(mergedTypedefs)];
}
}
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
GraphQLProjectConfig.prototype.loadDocuments = function (pointer) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!pointer) {
return [2 /*return*/, []];
}
return [2 /*return*/, this._extensionsRegistry.loaders.documents.loadDocuments(pointer)];
});
});
};
GraphQLProjectConfig.prototype.match = function (filepath) {
var _this = this;
var isSchemaOrDocument = [this.schema, this.documents].some(function (pointer) {
return match(filepath, _this.dirpath, pointer);
});
if (isSchemaOrDocument) {
return true;
}
var isExcluded = this.exclude
? match(filepath, this.dirpath, this.exclude)
: false;
if (isExcluded) {
return false;
}
var isIncluded = this.include
? match(filepath, this.dirpath, this.include)
: false;
if (isIncluded) {
return true;
}
return false;
};
return GraphQLProjectConfig;
}());
// XXX: it works but uses nodejs - expose normalization of file and dir paths in config
function match(filepath, dirpath, pointer) {
if (!pointer) {
return false;
}
if (Array.isArray(pointer)) {
return pointer.some(function (p) { return match(filepath, dirpath, p); });
}
if (typeof pointer === 'string') {
var normalizedFilepath = normalize(isAbsolute(filepath) ? relative(dirpath, filepath) : filepath);
return minimatch(normalizedFilepath, normalize(pointer), { dot: true });
}
if (typeof pointer === 'object') {
return match(filepath, dirpath, Object.keys(pointer)[0]);
}
return false;
}
var cwd = typeof process !== 'undefined' ? process.cwd() : undefined;

@@ -282,224 +412,35 @@ function isMultipleProjectConfig(config) {

}
function flatten(arr) {
var _a;
return (_a = Array.prototype).concat.apply(_a, arr);
}
function pick(key, items) {
return items.map(function (item) { return item[key]; });
}
var GraphQLProjectConfig = /** @class */ (function () {
function GraphQLProjectConfig(_a) {
var filepath = _a.filepath, name = _a.name, config = _a.config, extensionsRegistry = _a.extensionsRegistry;
this.filepath = filepath;
this.dirpath = dirname(filepath);
this.name = name;
this.extensions = config.extensions || {};
this.schema = config.schema;
this.documents = config.documents;
this.include = config.include;
this.exclude = config.exclude;
this._extensionsRegistry = extensionsRegistry;
var LoadersRegistry = /** @class */ (function () {
function LoadersRegistry(_a) {
var cwd = _a.cwd;
this._loaders = [];
this.cwd = cwd;
}
GraphQLProjectConfig.prototype.hasExtension = function (name) {
return !!this.extensions[name];
};
GraphQLProjectConfig.prototype.extension = function (name) {
var extension = this._extensionsRegistry.get(name);
if (!extension) {
throw new ExtensionMissingError("Project " + this.name + " is missing " + name + " extension");
LoadersRegistry.prototype.register = function (loader) {
if (!this._loaders.some(function (l) { return l.loaderId() === loader.loaderId(); })) {
this._loaders.push(loader);
}
return __assign(__assign({}, this.extensions[name]), { schema: this.schema, documents: this.documents, include: this.include, exclude: this.exclude });
};
GraphQLProjectConfig.prototype.getSchema = function (out) {
LoadersRegistry.prototype.loadTypeDefs = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.loadSchema(this.schema, out)];
return [2 /*return*/, loadTypedefs(pointer, __assign({ loaders: this._loaders, cwd: this.cwd }, options))];
});
});
};
GraphQLProjectConfig.prototype.getDocuments = function () {
LoadersRegistry.prototype.loadDocuments = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!this.documents) {
return [2 /*return*/, []];
}
return [2 /*return*/, this.loadDocuments(this.documents)];
return [2 /*return*/, loadDocuments(pointer, __assign({ loaders: this._loaders, cwd: this.cwd }, options))];
});
});
};
GraphQLProjectConfig.prototype.loadSchema = function (pointer, out) {
LoadersRegistry.prototype.loadSchema = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
var schema, schemas, _a, _b, _c;
var _this = this;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!Array.isArray(pointer)) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.all(pointer.map(function (_pointer) {
return _this._extensionsRegistry.loaders.schema.load(_pointer);
}))];
case 1:
schemas = _d.sent();
schema = mergeTypeDefs(flatten(schemas).map(function (s) { return s.document; }));
return [3 /*break*/, 4];
case 2:
_a = mergeTypeDefs;
_b = pick;
_c = ['document'];
return [4 /*yield*/, this._extensionsRegistry.loaders.schema.load(pointer)];
case 3:
schema = _a.apply(void 0, [_b.apply(void 0, _c.concat([_d.sent()]))]);
_d.label = 4;
case 4:
if (out === 'DocumentNode') {
return [2 /*return*/, schema];
}
return [2 /*return*/, buildASTSchema(schema)];
}
return __generator(this, function (_a) {
return [2 /*return*/, loadSchema(pointer, __assign({ loaders: this._loaders, cwd: this.cwd }, options))];
});
});
};
GraphQLProjectConfig.prototype.loadDocuments = function (pointer) {
return __awaiter(this, void 0, void 0, function () {
var _a;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!pointer) {
return [2 /*return*/, []];
}
if (!Array.isArray(pointer)) return [3 /*break*/, 2];
_a = flatten;
return [4 /*yield*/, Promise.all(pointer.map(function (_pointer) {
return _this._extensionsRegistry.loaders.documents.load(_pointer);
}))];
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
case 2: return [2 /*return*/, this._extensionsRegistry.loaders.documents.load(pointer)];
}
});
});
};
GraphQLProjectConfig.prototype.match = function (filepath) {
var _this = this;
var isSchemaOrDocument = [this.schema, this.documents].some(function (pointer) {
return match(filepath, _this.dirpath, pointer);
});
if (isSchemaOrDocument) {
return true;
}
var isExcluded = this.exclude
? match(filepath, this.dirpath, this.exclude)
: false;
if (isExcluded) {
return false;
}
var isIncluded = this.include
? match(filepath, this.dirpath, this.include)
: false;
if (isIncluded) {
return true;
}
return false;
};
return GraphQLProjectConfig;
}());
// XXX: it works but uses nodejs - expose normalization of file and dir paths in config
function match(filepath, dirpath, pointer) {
if (!pointer) {
return false;
}
if (Array.isArray(pointer)) {
return pointer.some(function (p) { return match(filepath, dirpath, p); });
}
if (typeof pointer === 'string') {
var normalizedFilepath = normalize(isAbsolute(filepath) ? relative(dirpath, filepath) : filepath);
return minimatch(normalizedFilepath, normalize(pointer), { dot: true });
}
if (typeof pointer === 'object') {
return match(filepath, dirpath, Object.keys(pointer)[0]);
}
return false;
}
function isGlob(pointer) {
return typeof pointer === 'string' && pointer.includes('*');
}
function isPointerWithConfiguration(pointer) {
var isObject = typeof pointer === 'object';
var hasOneKey = Object.keys(pointer).length === 1;
var key = Object.keys(pointer)[0];
var hasConfiguration = typeof pointer[key] === 'object';
return isObject && hasOneKey && hasConfiguration;
}
function isSourceArray(sources) {
return Array.isArray(sources);
}
var LoadersRegistry = /** @class */ (function () {
function LoadersRegistry(_a) {
var cwd = _a.cwd;
this._loaders = [];
this.cwd = cwd;
}
LoadersRegistry.prototype.register = function (loader) {
if (!this._loaders.some(function (l) { return l.loaderId() === loader.loaderId(); })) {
this._loaders.push(loader);
}
};
LoadersRegistry.prototype.load = function (pointer, options) {
return __awaiter(this, void 0, void 0, function () {
var globby, filepaths, results, key, _i, _a, loader, result;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!options) {
options = {};
}
options.cwd = this.cwd;
if (!isGlob(pointer)) return [3 /*break*/, 4];
return [4 /*yield*/, import('globby')];
case 1:
globby = (_b.sent()).default;
return [4 /*yield*/, globby(pointer, {
cwd: this.cwd,
})];
case 2:
filepaths = _b.sent();
return [4 /*yield*/, Promise.all(filepaths.map(function (filepath) { return _this.load(filepath, options); }))];
case 3:
results = _b.sent();
return [2 /*return*/, flatten(results.filter(isSourceArray))];
case 4:
if (isPointerWithConfiguration(pointer)) {
key = Object.keys(pointer)[0];
return [2 /*return*/, this.load(key, pointer[key])];
}
if (this._loaders.length === 0) {
throw new LoadersMissingError("Loaders are missing");
}
_i = 0, _a = this._loaders;
_b.label = 5;
case 5:
if (!(_i < _a.length)) return [3 /*break*/, 9];
loader = _a[_i];
return [4 /*yield*/, loader.canLoad(pointer, options)];
case 6:
if (!_b.sent()) return [3 /*break*/, 8];
return [4 /*yield*/, loader.load(pointer, options)];
case 7:
result = _b.sent();
if (result) {
return [2 /*return*/, [result]];
}
_b.label = 8;
case 8:
_i++;
return [3 /*break*/, 5];
case 9: throw new LoaderNoResultError("None of provided loaders could resolve: " + pointer);
}
});
});
};
return LoadersRegistry;

@@ -506,0 +447,0 @@ }());

@@ -1,3 +0,5 @@

import { Source, Loader, DocumentPointerSingle, SchemaPointerSingle } from '@graphql-toolkit/common';
export declare class LoadersRegistry<TPointer extends SchemaPointerSingle | DocumentPointerSingle> {
import { Source, Loader } from '@graphql-toolkit/common';
import { UnnormalizedTypeDefPointer, LoadTypedefsOptions } from '@graphql-toolkit/core';
import { GraphQLSchema } from 'graphql';
export declare class LoadersRegistry {
private _loaders;

@@ -8,5 +10,7 @@ private readonly cwd;

});
register(loader: Loader<TPointer>): void;
load(pointer: TPointer, options?: any): Promise<Source[]>;
register(loader: Loader): void;
loadTypeDefs(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], options?: Partial<LoadTypedefsOptions>): Promise<Source[]>;
loadDocuments(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], options?: Partial<LoadTypedefsOptions>): Promise<Source[]>;
loadSchema(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], options?: Partial<LoadTypedefsOptions>): Promise<GraphQLSchema>;
}
//# sourceMappingURL=loaders.d.ts.map
{
"name": "graphql-config",
"version": "3.0.0-alpha.15",
"version": "3.0.0-alpha.16",
"description": "The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)",

@@ -32,2 +32,3 @@ "peerDependencies": {

"@graphql-toolkit/common": "0.9.0",
"@graphql-toolkit/core": "0.9.0",
"@graphql-toolkit/graphql-file-loader": "0.9.0",

@@ -34,0 +35,0 @@ "@graphql-toolkit/json-file-loader": "0.9.0",

import { GraphQLSchema, DocumentNode } from 'graphql';
import { Source, SchemaPointer, DocumentPointer } from '@graphql-toolkit/common';
import { Source } from '@graphql-toolkit/common';
import { GraphQLExtensionsRegistry } from './extension';
import { IExtensions, IGraphQLProject } from './types';
import { UnnormalizedTypeDefPointer } from '@graphql-toolkit/core';
export declare class GraphQLProjectConfig {
readonly schema: SchemaPointer;
readonly documents?: DocumentPointer;
readonly schema: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
readonly documents?: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
readonly include?: string | string[];

@@ -26,9 +27,11 @@ readonly exclude?: string | string[];

getSchema(out: 'GraphQLSchema'): Promise<GraphQLSchema>;
getSchema(out: 'string'): Promise<string>;
getDocuments(): Promise<Source[]>;
loadSchema(pointer: SchemaPointer): Promise<GraphQLSchema>;
loadSchema(pointer: SchemaPointer, out: 'DocumentNode'): Promise<DocumentNode>;
loadSchema(pointer: SchemaPointer, out: 'GraphQLSchema'): Promise<GraphQLSchema>;
loadDocuments(pointer: DocumentPointer): Promise<Source[]>;
loadSchema(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[]): Promise<GraphQLSchema>;
loadSchema(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], out: 'string'): Promise<GraphQLSchema>;
loadSchema(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], out: 'DocumentNode'): Promise<DocumentNode>;
loadSchema(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], out: 'GraphQLSchema'): Promise<GraphQLSchema>;
loadDocuments(pointer: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[]): Promise<Source[]>;
match(filepath: string): boolean;
}
//# sourceMappingURL=project-config.d.ts.map

Sorry, the diff of this file is not supported yet

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