Socket
Socket
Sign inDemoInstall

graphql-introspection-filtering

Package Overview
Dependencies
9
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-alpha to 3.0.0-alpha.1

63

dist/classes/Introspection.js

@@ -1,10 +0,15 @@

import { defaultFieldResolver, introspectionTypes } from 'graphql';
import { INTROSPECTION_HOOK, SHOULD_HOOK_QUERY } from '../symbols';
import chainArray from '../tools/chainArray';
import chain from '../tools/chain';
import Manager from './Manager';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var graphql_1 = require("graphql");
var symbols_1 = require("../symbols");
var chainArray_1 = tslib_1.__importDefault(require("../tools/chainArray"));
var chain_1 = tslib_1.__importDefault(require("../tools/chain"));
var Manager_1 = tslib_1.__importDefault(require("./Manager"));
/**
* Introspection hook helper
*/
export default class Introspection {
var Introspection = /** @class */ (function () {
function Introspection() {
}
/**

@@ -15,9 +20,9 @@ * Hook Introspection schema resolver

*/
static hook(subject) {
if (subject[INTROSPECTION_HOOK]) {
Introspection.hook = function (subject) {
if (subject[symbols_1.INTROSPECTION_HOOK]) {
return;
}
subject[INTROSPECTION_HOOK] = true;
subject.resolve = Introspection.resolve.bind(subject.resolve || defaultFieldResolver);
}
subject[symbols_1.INTROSPECTION_HOOK] = true;
subject.resolve = Introspection.resolve.bind(subject.resolve || graphql_1.defaultFieldResolver);
};
/**

@@ -32,8 +37,8 @@ * Hooked introspection object/field/arg... resolver

*/
static resolve(root, args, context, info) {
const subject = this(root, args, context, info);
if (!subject || !(typeof subject === 'object') || info.operation[SHOULD_HOOK_QUERY] === false) {
Introspection.resolve = function (root, args, context, info) {
var subject = this(root, args, context, info);
if (!subject || !(typeof subject === 'object') || info.operation[symbols_1.SHOULD_HOOK_QUERY] === false) {
return subject;
}
const manager = Manager.extract(info.schema);
var manager = Manager_1.default.extract(info.schema);
if (manager) {

@@ -44,3 +49,3 @@ if (!Introspection.shouldHook(manager, context, info)) {

if (Array.isArray(subject)) {
const resolved = chainArray(subject, (item) => {
var resolved = (0, chainArray_1.default)(subject, function (item) {
if (Introspection.isExcluded(item)) {

@@ -51,3 +56,3 @@ return item;

});
return chain(resolved, (items) => items.filter(Boolean));
return (0, chain_1.default)(resolved, function (items) { return items.filter(Boolean); });
}

@@ -59,3 +64,3 @@ else if (!Introspection.isExcluded(subject)) {

return subject;
}
};
/**

@@ -67,5 +72,5 @@ * Exclude hooked and fundamental types

*/
static isExcluded(subject) {
Introspection.isExcluded = function (subject) {
// exclude already hooked top level objects/fields
if (subject[INTROSPECTION_HOOK]) {
if (subject[symbols_1.INTROSPECTION_HOOK]) {
return true;

@@ -78,4 +83,4 @@ }

// exclude rest of fundamental introspection types
return introspectionTypes.includes(subject);
}
return graphql_1.introspectionTypes.includes(subject);
};
/**

@@ -89,9 +94,11 @@ * Tells whether current introspection query be hooked

*/
static shouldHook(manager, context, info) {
if (info.operation[SHOULD_HOOK_QUERY] === undefined) {
info.operation[SHOULD_HOOK_QUERY] = manager.shouldHookQuery(context);
Introspection.shouldHook = function (manager, context, info) {
if (info.operation[symbols_1.SHOULD_HOOK_QUERY] === undefined) {
info.operation[symbols_1.SHOULD_HOOK_QUERY] = manager.shouldHookQuery(context);
}
return info.operation[SHOULD_HOOK_QUERY];
}
}
return info.operation[symbols_1.SHOULD_HOOK_QUERY];
};
return Introspection;
}());
exports.default = Introspection;
//# sourceMappingURL=Introspection.js.map

@@ -1,27 +0,19 @@

import { getDirectives } from '@graphql-tools/utils';
import { GraphQLDirective, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLScalarType, GraphQLUnionType } from 'graphql';
import { SCHEMA_MANAGER } from '../symbols';
import hasOwn from '../tools/hasOwn';
import clone from '../tools/clone';
import { IntrospectionMapperKind } from '../types';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var utils_1 = require("@graphql-tools/utils");
var graphql_1 = require("graphql");
var symbols_1 = require("../symbols");
var hasOwn_1 = tslib_1.__importDefault(require("../tools/hasOwn"));
var clone_1 = tslib_1.__importDefault(require("../tools/clone"));
var types_1 = require("../types");
/**
* Introspection schema hooks manager
*/
export default class Manager {
var Manager = /** @class */ (function () {
/**
* Extract Manager from schema
*
* @param schema graphql executable schema
*/
static extract(schema) {
if (hasOwn(schema, SCHEMA_MANAGER)) {
return schema[SCHEMA_MANAGER];
}
return undefined;
}
/**
* Manager constructor
* @param config schema configuration (definition)
*/
constructor(config) {
function Manager(config) {
this.SYMBOL_HOOK = Symbol('HOOK');

@@ -33,2 +25,13 @@ this._mappers = [];

/**
* Extract Manager from schema
*
* @param schema graphql executable schema
*/
Manager.extract = function (schema) {
if ((0, hasOwn_1.default)(schema, symbols_1.SCHEMA_MANAGER)) {
return schema[symbols_1.SCHEMA_MANAGER];
}
return undefined;
};
/**
* Enhanced schema resolver

@@ -42,7 +45,7 @@ *

*/
resolve(subject, root, args, context, info) {
if (!hasOwn(subject, this.SYMBOL_HOOK)) {
const cloned = clone(subject);
Manager.prototype.resolve = function (subject, root, args, context, info) {
if (!(0, hasOwn_1.default)(subject, this.SYMBOL_HOOK)) {
var cloned = (0, clone_1.default)(subject);
// @ts-ignore
cloned.resolve = cloned.resolve || (() => subject);
cloned.resolve = cloned.resolve || (function () { return subject; });
subject[this.SYMBOL_HOOK] = this.prepare(cloned, root, info.schema);

@@ -54,3 +57,3 @@ }

return subject[this.SYMBOL_HOOK].resolve(root, args, context, info);
}
};
/**

@@ -63,3 +66,3 @@ * It may be useful to occasionally not hook the introspection query

*/
shouldHookQuery(context) {
Manager.prototype.shouldHookQuery = function (context) {
if (typeof this._shouldSkipQuery === 'number') {

@@ -76,3 +79,3 @@ if (this._shouldSkipQuery > 0) {

return true;
}
};
/**

@@ -86,32 +89,32 @@ * Resolve visitor method for subject

// eslint-disable-next-line complexity
expectedMapperFor(subject, root) {
Manager.prototype.expectedMapperFor = function (subject, root) {
var _a, _b, _c;
switch (true) {
case subject instanceof GraphQLScalarType:
return IntrospectionMapperKind.SCALAR_TYPE;
case subject instanceof GraphQLDirective:
return IntrospectionMapperKind.DIRECTIVE;
case subject instanceof GraphQLInputObjectType:
return IntrospectionMapperKind.INPUT_OBJECT_TYPE;
case subject instanceof GraphQLEnumType:
return IntrospectionMapperKind.ENUM_TYPE;
case subject instanceof GraphQLInterfaceType:
return IntrospectionMapperKind.INTERFACE_TYPE;
case subject instanceof GraphQLUnionType:
return IntrospectionMapperKind.UNION_TYPE;
case subject instanceof GraphQLObjectType:
return IntrospectionMapperKind.OBJECT_TYPE;
case subject instanceof graphql_1.GraphQLScalarType:
return types_1.IntrospectionMapperKind.SCALAR_TYPE;
case subject instanceof graphql_1.GraphQLDirective:
return types_1.IntrospectionMapperKind.DIRECTIVE;
case subject instanceof graphql_1.GraphQLInputObjectType:
return types_1.IntrospectionMapperKind.INPUT_OBJECT_TYPE;
case subject instanceof graphql_1.GraphQLEnumType:
return types_1.IntrospectionMapperKind.ENUM_TYPE;
case subject instanceof graphql_1.GraphQLInterfaceType:
return types_1.IntrospectionMapperKind.INTERFACE_TYPE;
case subject instanceof graphql_1.GraphQLUnionType:
return types_1.IntrospectionMapperKind.UNION_TYPE;
case subject instanceof graphql_1.GraphQLObjectType:
return types_1.IntrospectionMapperKind.OBJECT_TYPE;
case ((_a = subject.astNode) === null || _a === void 0 ? void 0 : _a.kind) === 'FieldDefinition':
return IntrospectionMapperKind.OBJECT_FIELD;
return types_1.IntrospectionMapperKind.OBJECT_FIELD;
case ((_b = subject.astNode) === null || _b === void 0 ? void 0 : _b.kind) === 'EnumValueDefinition':
return IntrospectionMapperKind.ENUM_VALUE;
return types_1.IntrospectionMapperKind.ENUM_VALUE;
case ((_c = subject.astNode) === null || _c === void 0 ? void 0 : _c.kind) === 'InputValueDefinition':
if (root instanceof GraphQLInputObjectType) {
return IntrospectionMapperKind.INPUT_OBJECT_FIELD;
if (root instanceof graphql_1.GraphQLInputObjectType) {
return types_1.IntrospectionMapperKind.INPUT_OBJECT_FIELD;
}
return IntrospectionMapperKind.ARGUMENT;
return types_1.IntrospectionMapperKind.ARGUMENT;
default:
throw new Error('Visited unknown object!');
}
}
};
/**

@@ -125,32 +128,47 @@ * Prepare Hook for given subject

*/
prepare(subject, parent, schema) {
const directives = getDirectives(schema, subject) // todo consider always preparing
.filter(({ name }) => {
if (this._hookDirectives === true) {
Manager.prototype.prepare = function (subject, parent, schema) {
var e_1, _a;
var _this = this;
var directives = (0, utils_1.getDirectives)(schema, subject) // todo consider always preparing
.filter(function (_a) {
var name = _a.name;
if (_this._hookDirectives === true) {
return true;
}
if (this._hookDirectives === false) {
if (_this._hookDirectives === false) {
return false;
}
return this._hookDirectives.includes(name);
return _this._hookDirectives.includes(name);
});
let result = subject;
if (subject instanceof GraphQLDirective || directives.length > 0) {
const method = this.expectedMapperFor(subject, parent);
const filteredMappers = this._mappers
.filter((mapper) => {
return method && (method in mapper);
var result = subject;
if (subject instanceof graphql_1.GraphQLDirective || directives.length > 0) {
var method_1 = this.expectedMapperFor(subject, parent);
var filteredMappers = this._mappers
.filter(function (mapper) {
return method_1 && (method_1 in mapper);
});
for (const mapper of filteredMappers) {
// @ts-ignore
result = mapper[method](result, parent, schema); // todo
try {
for (var filteredMappers_1 = tslib_1.__values(filteredMappers), filteredMappers_1_1 = filteredMappers_1.next(); !filteredMappers_1_1.done; filteredMappers_1_1 = filteredMappers_1.next()) {
var mapper = filteredMappers_1_1.value;
// @ts-ignore
result = mapper[method_1](result, parent, schema); // todo
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (filteredMappers_1_1 && !filteredMappers_1_1.done && (_a = filteredMappers_1.return)) _a.call(filteredMappers_1);
}
finally { if (e_1) throw e_1.error; }
}
return result;
}
return false;
}
addMapper(schemaMapper) {
};
Manager.prototype.addMapper = function (schemaMapper) {
this._mappers.push(schemaMapper);
}
}
};
return Manager;
}());
exports.default = Manager;
//# sourceMappingURL=Manager.js.map

@@ -1,7 +0,12 @@

import { ONCE_CACHE } from '../symbols';
import OnceSession from './OnceSession';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var symbols_1 = require("../symbols");
var OnceSession_1 = tslib_1.__importDefault(require("./OnceSession"));
/**
* Resolves (and creates when needed) introspection query session managers from current request
*/
export default class Once {
var Once = /** @class */ (function () {
function Once() {
}
/**

@@ -11,5 +16,5 @@ * Creates new session manager

*/
newSession() {
return new OnceSession();
}
Once.prototype.newSession = function () {
return new OnceSession_1.default();
};
/**

@@ -20,8 +25,8 @@ * Extracts store from given queryContext (operation context)

*/
getStore(queryContext) {
if (!queryContext[ONCE_CACHE]) {
queryContext[ONCE_CACHE] = new Map();
Once.prototype.getStore = function (queryContext) {
if (!queryContext[symbols_1.ONCE_CACHE]) {
queryContext[symbols_1.ONCE_CACHE] = new Map();
}
return queryContext[ONCE_CACHE];
}
return queryContext[symbols_1.ONCE_CACHE];
};
/**

@@ -31,12 +36,14 @@ * Resolve session manager for given queryContext (operation context)

*/
session(queryContext) {
const store = this.getStore(queryContext);
Once.prototype.session = function (queryContext) {
var store = this.getStore(queryContext);
if (store.has(this)) {
return store.get(this);
}
const ses = this.newSession();
var ses = this.newSession();
store.set(this, ses);
return ses;
}
}
};
return Once;
}());
exports.default = Once;
//# sourceMappingURL=Once.js.map

@@ -0,6 +1,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Manages introspection query request repeated resolutions queue and cache for single field
*/
export default class OnceSession {
constructor() {
var OnceSession = /** @class */ (function () {
function OnceSession() {
this._awaiters = [];

@@ -10,12 +12,16 @@ this._started = false;

}
Object.defineProperty(OnceSession.prototype, "canJoin", {
/**
* Tells whether session can be joined.
*
* Returns true is session was started and is running or finished.
* Returns false if it wasn't started.
*/
get: function () {
return this._started || this._finished;
},
enumerable: false,
configurable: true
});
/**
* Tells whether session can be joined.
*
* Returns true is session was started and is running or finished.
* Returns false if it wasn't started.
*/
get canJoin() {
return this._started || this._finished;
}
/**
* Joins waiting session. If session was already finished session,

@@ -25,3 +31,4 @@ * the result is returned, if session is not finished yet awaiter promise is returned.

*/
join() {
OnceSession.prototype.join = function () {
var _this = this;
if (this._finished) {

@@ -31,6 +38,6 @@ return this._cache;

if (this._started) {
return new Promise((res) => this._awaiters.push(res));
return new Promise(function (res) { return _this._awaiters.push(res); });
}
throw new Error('Session not started!');
}
};
/**

@@ -41,3 +48,3 @@ * Starts session

*/
start() {
OnceSession.prototype.start = function () {
if (this._started) {

@@ -47,3 +54,3 @@ throw new Error('Session already started!');

this._started = true;
}
};
/**

@@ -54,11 +61,13 @@ * Completes session and saves it's result for late comers

*/
complete(value) {
OnceSession.prototype.complete = function (value) {
this._cache = value;
this._finished = true;
this._started = false;
const awaiters = this._awaiters;
var awaiters = this._awaiters;
this._awaiters = [];
setImmediate(() => awaiters.forEach((res) => res(value)));
}
}
setImmediate(function () { return awaiters.forEach(function (res) { return res(value); }); });
};
return OnceSession;
}());
exports.default = OnceSession;
//# sourceMappingURL=OnceSession.js.map

@@ -0,6 +1,16 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntrospectionMapperKind = exports.mapSchema = exports.makeExecutableSchema = exports.default = void 0;
// eslint-disable-next-line import/no-unassigned-import
import './register';
export { default, default as makeExecutableSchema } from './tools/makeExecutableSchema';
export { default as mapSchema } from './tools/mapSchema';
export { IntrospectionMapperKind } from './types';
require("./register");
var makeExecutableSchema_1 = require("./tools/makeExecutableSchema");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(makeExecutableSchema_1).default; } });
Object.defineProperty(exports, "makeExecutableSchema", { enumerable: true, get: function () { return __importDefault(makeExecutableSchema_1).default; } });
var mapSchema_1 = require("./tools/mapSchema");
Object.defineProperty(exports, "mapSchema", { enumerable: true, get: function () { return __importDefault(mapSchema_1).default; } });
var types_1 = require("./types");
Object.defineProperty(exports, "IntrospectionMapperKind", { enumerable: true, get: function () { return types_1.IntrospectionMapperKind; } });
// todo remove directives, check mappers

@@ -7,0 +17,0 @@ // todo add comments

@@ -1,13 +0,16 @@

import { TypeMetaFieldDef, __Schema, __Type, __Field } from 'graphql/type/introspection';
import Introspection from './classes/Introspection';
Introspection.hook(TypeMetaFieldDef);
Introspection.hook(__Schema.getFields().types);
Introspection.hook(__Schema.getFields().directives);
Introspection.hook(__Type.getFields().fields);
Introspection.hook(__Type.getFields().enumValues);
Introspection.hook(__Type.getFields().inputFields);
Introspection.hook(__Type.getFields().possibleTypes);
Introspection.hook(__Field.getFields().args);
Introspection.hook(__Schema.getFields().mutationType);
Introspection.hook(__Schema.getFields().subscriptionType);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var introspection_1 = require("graphql/type/introspection");
var Introspection_1 = tslib_1.__importDefault(require("./classes/Introspection"));
Introspection_1.default.hook(introspection_1.TypeMetaFieldDef);
Introspection_1.default.hook(introspection_1.__Schema.getFields().types);
Introspection_1.default.hook(introspection_1.__Schema.getFields().directives);
Introspection_1.default.hook(introspection_1.__Type.getFields().fields);
Introspection_1.default.hook(introspection_1.__Type.getFields().enumValues);
Introspection_1.default.hook(introspection_1.__Type.getFields().inputFields);
Introspection_1.default.hook(introspection_1.__Type.getFields().possibleTypes);
Introspection_1.default.hook(introspection_1.__Field.getFields().args);
Introspection_1.default.hook(introspection_1.__Schema.getFields().mutationType);
Introspection_1.default.hook(introspection_1.__Schema.getFields().subscriptionType);
//# sourceMappingURL=register.js.map

@@ -1,5 +0,8 @@

export const INTROSPECTION_HOOK = Symbol('INTROSPECTION_HOOK');
export const SCHEMA_MANAGER = Symbol('SCHEMA_MANAGER');
export const SHOULD_HOOK_QUERY = Symbol('SHOULD_HOOK_QUERY');
export const ONCE_CACHE = Symbol('ONCE_CACHE');
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ONCE_CACHE = exports.SHOULD_HOOK_QUERY = exports.SCHEMA_MANAGER = exports.INTROSPECTION_HOOK = void 0;
exports.INTROSPECTION_HOOK = Symbol('INTROSPECTION_HOOK');
exports.SCHEMA_MANAGER = Symbol('SCHEMA_MANAGER');
exports.SHOULD_HOOK_QUERY = Symbol('SHOULD_HOOK_QUERY');
exports.ONCE_CACHE = Symbol('ONCE_CACHE');
//# sourceMappingURL=symbols.js.map

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

import isPromise from './isPromise';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var isPromise_1 = tslib_1.__importDefault(require("./isPromise"));
/**

@@ -7,9 +10,9 @@ * Executes fn on resolver value or Promise

*/
export default (valueOrPromise, fn) => {
if (isPromise(valueOrPromise)) {
const promise = valueOrPromise;
exports.default = (function (valueOrPromise, fn) {
if ((0, isPromise_1.default)(valueOrPromise)) {
var promise = valueOrPromise;
return promise.then(fn);
}
return fn(valueOrPromise);
};
});
//# sourceMappingURL=chain.js.map

@@ -1,3 +0,6 @@

import chain from './chain';
import isPromise from './isPromise';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chain_1 = tslib_1.__importDefault(require("./chain"));
var isPromise_1 = tslib_1.__importDefault(require("./isPromise"));
/**

@@ -11,12 +14,23 @@ * Maps array of items of given types with `fn` callback,

*/
export default (array, fn) => {
const items = [];
let promise = false;
for (const item of array) {
const chained = chain(item, fn);
if (isPromise(chained)) {
promise = true;
exports.default = (function (array, fn) {
var e_1, _a;
var items = [];
var promise = false;
try {
for (var array_1 = tslib_1.__values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
var item = array_1_1.value;
var chained = (0, chain_1.default)(item, fn);
if ((0, isPromise_1.default)(chained)) {
promise = true;
}
items.push(chained);
}
items.push(chained);
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
}
finally { if (e_1) throw e_1.error; }
}
if (promise) {

@@ -26,3 +40,3 @@ return Promise.all(items);

return items;
};
});
//# sourceMappingURL=chainArray.js.map

@@ -0,5 +1,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// todo tests comment
export default function clone(input) {
function clone(input) {
return Object.assign(Object.create(Object.getPrototypeOf(input)), input);
}
exports.default = clone;
//# sourceMappingURL=clone.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -7,3 +9,3 @@ * Object.prototype.hasOwnProperty helper

*/
export default (target, prop) => Object.prototype.hasOwnProperty.call(target, prop);
exports.default = (function (target, prop) { return Object.prototype.hasOwnProperty.call(target, prop); });
//# sourceMappingURL=hasOwn.js.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -6,5 +8,5 @@ * Check whether provided subject is a Promise

*/
export default (subject) => {
exports.default = (function (subject) {
return subject && subject.then && typeof subject.then === 'function';
};
});
//# sourceMappingURL=isPromise.js.map

@@ -1,4 +0,7 @@

import { makeExecutableSchema } from '@graphql-tools/schema';
import Manager from '../classes/Manager';
import { SCHEMA_MANAGER } from '../symbols';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var schema_1 = require("@graphql-tools/schema");
var Manager_1 = tslib_1.__importDefault(require("../classes/Manager"));
var symbols_1 = require("../symbols");
/**

@@ -10,7 +13,8 @@ * Create graphql executable schema with injected Manager

*/
export default (config, builder = makeExecutableSchema) => {
const schema = builder(config);
schema[SCHEMA_MANAGER] = new Manager(config);
exports.default = (function (config, builder) {
if (builder === void 0) { builder = schema_1.makeExecutableSchema; }
var schema = builder(config);
schema[symbols_1.SCHEMA_MANAGER] = new Manager_1.default(config);
return schema;
};
});
//# sourceMappingURL=makeExecutableSchema.js.map

@@ -1,5 +0,8 @@

import { mapSchema } from '@graphql-tools/utils';
import { SCHEMA_MANAGER } from '../symbols';
import { isIntrospectionMapper } from '../types';
import hasOwn from './hasOwn';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var utils_1 = require("@graphql-tools/utils");
var symbols_1 = require("../symbols");
var types_1 = require("../types");
var hasOwn_1 = tslib_1.__importDefault(require("./hasOwn"));
/**

@@ -11,20 +14,41 @@ * Maps schema hoisting schema prototype and additional properties

*/
export default (schema, schemaMapper) => {
const mapped = mapSchema(schema, schemaMapper);
for (const sym of Object.getOwnPropertySymbols(schema)) {
mapped[sym] = schema[sym];
exports.default = (function (schema, schemaMapper) {
var e_1, _a, e_2, _b;
var mapped = (0, utils_1.mapSchema)(schema, schemaMapper);
try {
for (var _c = tslib_1.__values(Object.getOwnPropertySymbols(schema)), _d = _c.next(); !_d.done; _d = _c.next()) {
var sym = _d.value;
mapped[sym] = schema[sym];
}
}
for (const key of Object.getOwnPropertyNames(schema)) {
if (!hasOwn(mapped, key)) {
mapped[key] = schema[key];
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
finally { if (e_1) throw e_1.error; }
}
if (isIntrospectionMapper(schemaMapper)) {
if (!(SCHEMA_MANAGER in mapped)) {
try {
for (var _e = tslib_1.__values(Object.getOwnPropertyNames(schema)), _f = _e.next(); !_f.done; _f = _e.next()) {
var key = _f.value;
if (!(0, hasOwn_1.default)(mapped, key)) {
mapped[key] = schema[key];
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
if ((0, types_1.isIntrospectionMapper)(schemaMapper)) {
if (!(symbols_1.SCHEMA_MANAGER in mapped)) {
throw new Error('IntrospectionSchemaMapper can be used with filtered schema only');
}
mapped[SCHEMA_MANAGER].addMapper(schemaMapper);
mapped[symbols_1.SCHEMA_MANAGER].addMapper(schemaMapper);
}
return mapped;
};
});
//# sourceMappingURL=mapSchema.js.map

@@ -1,34 +0,23 @@

// todo
export var IntrospectionMapperKind;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isIntrospectionMapper = exports.INTROSPECTION_MAPPER_KEYS = exports.IntrospectionMapperKind = void 0;
var tslib_1 = require("tslib");
var IntrospectionMapperKind;
(function (IntrospectionMapperKind) {
// TYPE = 'IntrospectionMapperKind.TYPE',
IntrospectionMapperKind["SCALAR_TYPE"] = "IntrospectionMapperKind.SCALAR_TYPE";
IntrospectionMapperKind["ENUM_TYPE"] = "IntrospectionMapperKind.ENUM_TYPE";
// COMPOSITE_TYPE = 'IntrospectionMapperKind.COMPOSITE_TYPE',
IntrospectionMapperKind["OBJECT_TYPE"] = "IntrospectionMapperKind.OBJECT_TYPE";
IntrospectionMapperKind["INPUT_OBJECT_TYPE"] = "IntrospectionMapperKind.INPUT_OBJECT_TYPE";
// ABSTRACT_TYPE = 'IntrospectionMapperKind.ABSTRACT_TYPE',
IntrospectionMapperKind["UNION_TYPE"] = "IntrospectionMapperKind.UNION_TYPE";
IntrospectionMapperKind["INTERFACE_TYPE"] = "IntrospectionMapperKind.INTERFACE_TYPE";
// ROOT_OBJECT = 'IntrospectionMapperKind.ROOT_OBJECT',
// QUERY = 'IntrospectionMapperKind.QUERY',
// MUTATION = 'IntrospectionMapperKind.MUTATION',
// SUBSCRIPTION = 'IntrospectionMapperKind.SUBSCRIPTION',
IntrospectionMapperKind["DIRECTIVE"] = "IntrospectionMapperKind.DIRECTIVE";
// FIELD = 'IntrospectionMapperKind.FIELD',
// COMPOSITE_FIELD = 'IntrospectionMapperKind.COMPOSITE_FIELD',
IntrospectionMapperKind["OBJECT_FIELD"] = "IntrospectionMapperKind.OBJECT_FIELD";
// ROOT_FIELD = 'IntrospectionMapperKind.ROOT_FIELD',
// QUERY_ROOT_FIELD = 'IntrospectionMapperKind.QUERY_ROOT_FIELD',
// MUTATION_ROOT_FIELD = 'IntrospectionMapperKind.MUTATION_ROOT_FIELD',
// SUBSCRIPTION_ROOT_FIELD = 'IntrospectionMapperKind.SUBSCRIPTION_ROOT_FIELD',
// INTERFACE_FIELD = 'IntrospectionMapperKind.INTERFACE_FIELD',
IntrospectionMapperKind["INPUT_OBJECT_FIELD"] = "IntrospectionMapperKind.INPUT_OBJECT_FIELD";
IntrospectionMapperKind["ARGUMENT"] = "IntrospectionMapperKind.ARGUMENT";
IntrospectionMapperKind["ENUM_VALUE"] = "IntrospectionMapperKind.ENUM_VALUE";
})(IntrospectionMapperKind || (IntrospectionMapperKind = {}));
})(IntrospectionMapperKind || (exports.IntrospectionMapperKind = IntrospectionMapperKind = {}));
/**
* List of all supported IntrospectionSchemaFieldMappers
*/
export const INTROSPECTION_MAPPER_KEYS = [
exports.INTROSPECTION_MAPPER_KEYS = [
IntrospectionMapperKind.SCALAR_TYPE,

@@ -49,10 +38,22 @@ IntrospectionMapperKind.ENUM_TYPE,

*/
export const isIntrospectionMapper = (value) => {
for (const key of Object.keys(value || {})) {
if (INTROSPECTION_MAPPER_KEYS.includes(key)) {
return true;
var isIntrospectionMapper = function (value) {
var e_1, _a;
try {
for (var _b = tslib_1.__values(Object.keys(value || {})), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;
if (exports.INTROSPECTION_MAPPER_KEYS.includes(key)) {
return true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return false;
};
exports.isIntrospectionMapper = isIntrospectionMapper;
//# sourceMappingURL=types.js.map
{
"name": "graphql-introspection-filtering",
"version": "3.0.0-alpha",
"version": "3.0.0-alpha.1",
"description": "Filter graphql schema introspection result to hide restricted fields and types",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

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

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

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

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc