Gathering detailed insights and metrics for @iksena/graphql-constraint-directive
Gathering detailed insights and metrics for @iksena/graphql-constraint-directive
Gathering detailed insights and metrics for @iksena/graphql-constraint-directive
Gathering detailed insights and metrics for @iksena/graphql-constraint-directive
npm install @iksena/graphql-constraint-directive
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
49 Commits
1 Forks
5 Branches
1 Contributors
Updated on Feb 06, 2021
Latest Version
1.0.0
Package Id
@iksena/graphql-constraint-directive@1.0.0
Unpacked Size
101.40 kB
Size
8.77 kB
File Count
23
NPM Version
6.14.9
Node Version
14.15.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
Allows using @constraint as a directive to validate input data. Inspired by Constraints Directives RFC and OpenAPI
Forked from graphql-constraint-directive to use SchemaDirectiveVisitor and make it compatible with Apollo Federation
npm install @iksena/graphql-constraint-directive
1const { ConstraintDirective, constraintDirectiveTypeDefs } = require('@iksena/graphql-constraint-directive'); 2const express = require('express'); 3const { ApolloServer, SchemaDirectiveVisitor, makeExecutableSchema } = require('apollo-server-express'); 4const typeDefs = ` 5 type Query { 6 books: [Book] 7 } 8 type Book { 9 title: String 10 } 11 type Mutation { 12 createBook(input: BookInput): Book 13 } 14 input BookInput { 15 title: String! @constraint(minLength: 5, format: "email") 16 } 17`; 18const schema = makeExecutableSchema({ 19 typeDefs: [constraintDirectiveTypeDefs, typeDefs] 20}); 21SchemaDirectiveVisitor.visitSchemaDirectives(schema, { 22 constraint: ConstraintDirective 23}); 24const app = express(); 25const server = new ApolloServer({ schema }); 26 27server.applyMiddleware({ app }); 28
@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(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
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 binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
38 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