graphql-introspection-filtering
Advanced tools
Comparing version 2.0.0-alpha.0 to 2.0.0-alpha.1
@@ -1,2 +0,2 @@ | ||
import type { GraphQLResolveInfo } from 'graphql'; | ||
import type { GraphQLResolveInfo, GraphQLField } from 'graphql'; | ||
import type { VisitableIntrospectionType } from '../types'; | ||
@@ -7,2 +7,5 @@ export default class Introspection { | ||
protected static isExcluded(item: VisitableIntrospectionType): boolean; | ||
static hookRoot<S, TContext, TArgs = { | ||
[key: string]: any; | ||
}>(subject: GraphQLField<S, TContext, TArgs>, typeName: string): void; | ||
} |
@@ -78,3 +78,3 @@ "use strict"; | ||
} | ||
if (!item.astNode) { // todo rules out queryType, mutationType, and subscriptionType | ||
if (!item.astNode) { | ||
return true; | ||
@@ -84,2 +84,34 @@ } | ||
}; | ||
Introspection.hookRoot = function (subject, typeName) { | ||
var originalResolver = subject.resolve || graphql_1.defaultFieldResolver; | ||
subject.resolve = function (root, args, context, info) { | ||
var _a; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var resolver, manager, typesResolver, types, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, originalResolver(root, args, context, info)]; | ||
case 1: | ||
resolver = _c.sent(); | ||
manager = Manager_1.default.extract(info.schema); | ||
if (!manager) return [3 /*break*/, 4]; | ||
typesResolver = (_a = graphql_1.__Schema.getFields().types) === null || _a === void 0 ? void 0 : _a.resolve; | ||
_b = typesResolver; | ||
if (!_b) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, typesResolver(root, args, context, info)]; | ||
case 2: | ||
_b = (_c.sent()); | ||
_c.label = 3; | ||
case 3: | ||
types = _b; | ||
if (types && !types.some(function (field) { return field.name === typeName; })) { | ||
return [2 /*return*/, null]; | ||
} | ||
_c.label = 4; | ||
case 4: return [2 /*return*/, resolver]; | ||
} | ||
}); | ||
}); | ||
}; | ||
}; | ||
return Introspection; | ||
@@ -86,0 +118,0 @@ }()); |
@@ -14,5 +14,4 @@ "use strict"; | ||
Introspection_1.default.hook(introspection_1.__Field.getFields().args); | ||
// Introspection.hook(__Schema.getFields().queryType, 'Query'); | ||
// Introspection.hook(__Schema.getFields().mutationType, 'Mutation'); | ||
// Introspection.hook(__Schema.getFields().subscriptionType, 'Subscription'); | ||
Introspection_1.default.hookRoot(introspection_1.__Schema.getFields().mutationType, 'Mutation'); | ||
Introspection_1.default.hookRoot(introspection_1.__Schema.getFields().subscriptionType, 'Subscription'); | ||
//# sourceMappingURL=register.js.map |
import type { GraphQLArgument, GraphQLDirective, GraphQLEnumType, GraphQLEnumValue, GraphQLField, GraphQLInputField, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema, GraphQLUnionType } from 'graphql'; | ||
import type { SchemaDirectiveVisitor, VisitableSchemaType } from 'graphql-tools/dist/schemaVisitor'; | ||
export declare type VisitableIntrospectionType = GraphQLScalarType | GraphQLObjectType | GraphQLInputField | GraphQLField<any, any> | GraphQLEnumType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumValue | GraphQLArgument | GraphQLInputObjectType | GraphQLDirective; | ||
export declare type IntrospectionVisitor<T> = (result: T, info: GraphQLResolveInfo) => Promise<T | null> | T | null; | ||
export declare type VisitorResult<T> = Promise<T | null> | T | null; | ||
export declare type IntrospectionVisitor<T> = (result: T, info: GraphQLResolveInfo) => VisitorResult<T>; | ||
export interface IntrospectionDirectiveVisitor extends SchemaDirectiveVisitor { | ||
@@ -6,0 +7,0 @@ visitIntrospectionScalar?: IntrospectionVisitor<GraphQLScalarType>; |
{ | ||
"name": "graphql-introspection-filtering", | ||
"version": "2.0.0-alpha.0", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Filter graphql schema introspection result to hide restricted fields and types", | ||
@@ -18,5 +18,6 @@ "main": "./dist/index.js", | ||
"build": "yarn clean && tsc", | ||
"lint": "eslint --ext .ts --cache src", | ||
"lint": "eslint --ext .ts --cache src tests", | ||
"prepare": "yarn build", | ||
"test": "jest --config .jestrc.json" | ||
"test": "jest --config .jestrc.json", | ||
"example": "ts-node -P ./tsconfig.all.json ./example/index.ts" | ||
}, | ||
@@ -37,2 +38,3 @@ "author": "Adam Makświej <adam.makswiej@gmail.com>", | ||
"devDependencies": { | ||
"@types/express": "^4.17.11", | ||
"@types/graphql": "14.0.2", | ||
@@ -47,2 +49,4 @@ "@types/jest": "^26.0.20", | ||
"eslint-plugin-no-only-tests": "^2.4.0", | ||
"express": "^4.17.1", | ||
"express-graphql": "^0.12.0", | ||
"graphql": "^14.0.0", | ||
@@ -53,2 +57,3 @@ "graphql-tools": "^4.0.0", | ||
"ts-jest": "^26.5.0", | ||
"ts-node": "^9.1.1", | ||
"tslib": "^2.1.0", | ||
@@ -55,0 +60,0 @@ "typescript": "^4.1.3" |
@@ -11,2 +11,6 @@ # graphql-introspection-filtering | ||
> **NOTE:** `Query` type definition is required | ||
> **NOTE:** Object types must contain at least one visible field | ||
**Tested with GraphQL 14.0.0 - ...** | ||
@@ -161,18 +165,13 @@ | ||
# TODO | ||
* test subscriptions and mutations | ||
* empty objects and empty root objects (unions, interfaces) | ||
* running examples (integration mock schemas * roles) in playground without errors | ||
* custom scalars? | ||
* query, mutation, subscription, variable, fragment?? | ||
* cleanup unused children | ||
* cleanup children of filtered parent | ||
* unit tests | ||
* test if all visitors get all data | ||
* directive test dummy? | ||
* inspect throws and any's, todos | ||
* test gql 15 | ||
* update docs | ||
* unit tests | ||
* test if visitors get all data | ||
* directive test dummy? | ||
* ability to manipulate ast??? | ||
* check for privates before snapshot | ||
* mutate description?? | ||
@@ -184,1 +183,3 @@ # DONE | ||
* split visit intorspection type to object/enum/union/interface/input | ||
* test subscriptions and mutations | ||
* ability to manipulate ast??? |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
41183
29
479
183
0
20