Gathering detailed insights and metrics for @karavaan/graphql-constraint-directive
Gathering detailed insights and metrics for @karavaan/graphql-constraint-directive
Gathering detailed insights and metrics for @karavaan/graphql-constraint-directive
Gathering detailed insights and metrics for @karavaan/graphql-constraint-directive
npm install @karavaan/graphql-constraint-directive
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (99.89%)
TypeScript (0.11%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
573 Stars
201 Commits
74 Forks
5 Watchers
14 Branches
35 Contributors
Updated on Jul 09, 2025
Latest Version
2.1.4
Package Id
@karavaan/graphql-constraint-directive@2.1.4
Unpacked Size
305.46 kB
Size
84.10 kB
File Count
32
NPM Version
6.14.7
Node Version
14.17.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
1
Allows using @constraint as a directive to validate input data. Inspired by Constraints Directives RFC and OpenAPI
npm install graphql-constraint-directive
1const { constraintDirective, constraintDirectiveTypeDefs } = require('graphql-constraint-directive') 2const express = require('express') 3const { ApolloServer } = require('apollo-server-express') 4const { makeExecutableSchema } = require('graphql-tools') 5const typeDefs = ` 6 type Query { 7 books: [Book] 8 } 9 type Book { 10 title: String 11 } 12 type Mutation { 13 createBook(input: BookInput): Book 14 } 15 input BookInput { 16 title: String! @constraint(minLength: 5, format: "email") 17 }` 18const schema = makeExecutableSchema({ 19 typeDefs: [constraintDirectiveTypeDefs, typeDefs], 20 schemaTransforms: [constraintDirective()] 21}) 22const app = express() 23const server = new ApolloServer({ schema }) 24 25server.applyMiddleware({ app }) 26
@constraint(minLength: 5)
Restrict to a minimum length
@constraint(maxLength: 5)
Restrict to a maximum length
@constraint(startsWith: "foo")
Ensure value starts with foo
@constraint(endsWith: "foo")
Ensure value ends with foo
@constraint(contains: "foo")
Ensure value contains foo
@constraint(notContains: "foo")
Ensure value does not contain foo
@constraint(pattern: "^[0-9a-zA-Z]*$")
Ensure value matches regex, e.g. alphanumeric
@constraint(format: "email")
Ensure value is in a particular format
Supported formats:
@constraint(oneOf: ['test', 'hello'])
Value should be equal to one of the strings supplied
@constraint(min: 3)
Ensure value is greater than or equal to
@constraint(max: 3)
Ensure value is less than or equal to
@constraint(exclusiveMin: 3)
Ensure value is greater than
@constraint(exclusiveMax: 3)
Ensure value is less than
@constraint(multipleOf: 10)
Ensure value is a multiple
@constraint(minListLengt: 10)
Ensure list length is greater than
@constraint(maxListLengt: 10)
Ensure list length is less than
Each validation error throws a ConstraintDirectiveError
. Combined with a formatError function, this can be used to customise error messages.
1{ 2 code: 'ERR_GRAPHQL_CONSTRAINT_VALIDATION', 3 fieldName: 'theFieldName', 4 context: [ { arg: 'argument name which failed', value: 'value of argument' } ] 5}
1const formatError = function (error) { 2 if (error.originalError && error.originalError.code === 'ERR_GRAPHQL_CONSTRAINT_VALIDATION') { 3 // return a custom object 4 } 5 6 return error 7} 8 9app.use('/graphql', bodyParser.json(), graphqlExpress({ schema, formatError })) 10
@constraint(uniqueTypeName: "Unique_Type_Name")
Override the unique type name generate by the library to the one passed as an argument
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More