Registry /
security / graphql-introspection-filtering
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);
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.
fixEnsure 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).
fixAdd 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.
fixAdd 'type Query { dummy: String }' to your typeDefs. 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