Registry / security / graphql-introspection-filtering

graphql-introspection-filtering

JSON →
library3.0.0jsnpmunverified

GraphQL library to filter introspection query results by hiding restricted fields and types using schema mappers and directives. Current stable version: 3.0.0. Maintained actively, tested with GraphQL 16.6.0 and @graphql-tools 8.0.0-10.0.0. Key differentiator: allows conditional filtering based on context, supports skipping unfiltered queries, and integrates with makeExecutableSchema. Requires peer dependencies graphql >=14.0.0, @graphql-tools/schema >=8.0.0, and @graphql-tools/utils >=8.0.0. Ships TypeScript type definitions.

npm install graphql-introspection-filtering
INSTALL
IMPORT
SIG · GRAPHQL-INTROSPECT
G
graphql-introspection-filtering
securityjavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

makeExecutableSchema
import { makeExecutableSchema } from 'graphql-introspection-filtering'
import { makeExecutableSchema } from '@graphql-tools/schema'
The package re-exports and extends makeExecutableSchema from @graphql-tools/schema with introspection filtering support.
mapSchema
import { mapSchema } from 'graphql-introspection-filtering'
import { mapSchema } from '@graphql-tools/utils'
This mapSchema is the introspection-aware version that applies the mapper to filter introspection results.
IntrospectionMapperKind
import { IntrospectionMapperKind } from 'graphql-introspection-filtering'
Enum used to define mapper keys for different schema types. No CommonJS export for this symbol.

Creates a GraphQL schema with a @restricted directive and filters introspection to hide restricted fields and types.

import { makeExecutableSchema, mapSchema, IntrospectionMapperKind } from 'graphql-introspection-filtering'; const typeDefs = ` directive @restricted on OBJECT | FIELD_DEFINITION type Query { publicField: String secretField: String @restricted } `; const resolvers = { Query: { publicField: () => 'public', secretField: () => 'secret', }, }; const mapper = { [IntrospectionMapperKind.OBJECT_TYPE](result, parent, schema) { if (result.astNode?.directives?.some(d => d.name.value === 'restricted')) { return null; } return result; }, [IntrospectionMapperKind.FIELD](result, parent, schema) { if (result.astNode?.directives?.some(d => d.name.value === 'restricted')) { return null; } return result; }, }; const schema = makeExecutableSchema({ typeDefs, resolvers }); const filteredSchema = mapSchema(schema, mapper); console.log(filteredSchema);
Debug
Known issues
gotchaMissing dependent types cause introspection failure: if a type is filtered out but referenced by a visible field, the client cannot rebuild the schema.
fix
Ensure that all types referenced by visible fields are also visible, or provide stub types.
affects: >=1.0.0
gotchaQuery type must be defined in the schema, otherwise filtering will not work.
fix
Add a Query type with at least one field to your schema definition.
affects: >=1.0.0
gotchaObject types must contain at least one visible field; if all fields are filtered, the type will cause introspection errors.
fix
Ensure each visible object type has at least one field that is not filtered out.
affects: >=1.0.0
deprecatedLegacy graphql-tools versions before 8.0.0 are no longer supported. Use release 2.1.0 for older graphql-tools.
fix
Upgrade to @graphql-tools/schema >=8.0.0 or pin graphql-introspection-filtering to version 2.1.0.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot use GraphQLSchema "[object Object]" from another module or realm.
Multiple instances of graphql package in node_modules causing type mismatch.
fix
Ensure only one version of graphql is installed using npm dedupe or yarn resolutions.
TypeError: mapper[IntrospectionMapperKind.OBJECT_TYPE] is not a function
Mapper object does not include all required keys (e.g., FIELD).
fix
Add the missing mapper kind function, at least for FIELD if not all types.
Error: Query root type must be provided.
Schema definition does not include a Query type.
fix
Add 'type Query { dummy: String }' to your typeDefs.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency for GraphQL schema and introspection types
@graphql-tools/schemarequiredPeer dependency for makeExecutableSchema and schema manipulation
@graphql-tools/utilsrequiredPeer dependency for GraphQL utilities, e.g., mapSchema
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
graphql-introspection-filtering — npm install graphql-introspection-filtering · libregistry