Validate GraphQL input fields using @constraint directive, inspired by the Constraints Directives RFC and OpenAPI. Current stable version is 6.0.0, with frequent releases tracking GraphQL ecosystem changes. Key differentiator: works as a schema wrapper (modifies schema, validates both input and response) or as server plugins (Envelop, Apollo) that keep schema unmodified but only validate incoming queries. Supports constraints like minLength, maxLength, format (regex), minimum, maximum, pattern, etc. Requires peer dependency graphql >=14.0.0. Ships TypeScript definitions.
npm install graphql-constraint-directiveNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a GraphQL schema with @constraint validation on input fields using the schema wrapper approach.
Use import statements or update require() to destructure correctly: use require('graphql-constraint-directive') and access .constraintDirective (not .default).Check Apollo Server version: use createApolloQueryValidationPlugin for Apollo 3, createApollo4QueryValidationPlugin for Apollo 4.
Use named exports from main module. Remove dependency on 'graphql-constraint-directive/typeDefs' path.
If you need unmodified schema, use the plugin approach (Envelop or Apollo) instead of schema wrapper.
Choose schema wrapper if you need response validation; otherwise use plugins for query-only validation.
Use import { constraintDirective } from 'graphql-constraint-directive' and then apply it: constraintDirective()(schema).Add constraintDirectiveTypeDefs to the typeDefs array in makeExecutableSchema.
Use import { constraintDirectiveTypeDefs } from 'graphql-constraint-directive' instead of from subpath.Ensure constraintDirectiveTypeDefs is included in typeDefs array when calling makeExecutableSchema.