New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

graphql-constraint-directive

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-constraint-directive - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1

11

lib/query-validation-visitor.js

@@ -189,2 +189,4 @@ const { getVariableValues } = require('graphql/execution/values.js')

let hasNonListValidation = false
if (directiveArgumentMap) {

@@ -209,2 +211,9 @@ let errMessageBase

}
for (const key in directiveArgumentMap) {
if (key !== 'maxItems' && key !== 'minItems') {
hasNonListValidation = true
break
}
}
}

@@ -219,3 +228,3 @@

validateInputTypeValue(context, valueTypeDefArray, argName, variableName, element, currentField, iFieldNameFullIndexed)
} else {
} else if (hasNonListValidation) {
const atMessage = ` at "${iFieldNameFullIndexed}"`

@@ -222,0 +231,0 @@

2

package.json
{
"name": "graphql-constraint-directive",
"version": "4.1.0",
"version": "4.1.1",
"description": "Validate GraphQL fields",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,3 +6,3 @@ const { deepStrictEqual, strictEqual } = require('assert')

describe('Array size', function () {
describe('Input object', function () {
describe('Inside Input Object', function () {
const query = `mutation createBook($input: BookInput) {

@@ -130,3 +130,3 @@ createBook(input: $input) {

describe('Input argument', function () {
describe('Scalar argument', function () {
describe('#minItems', function () {

@@ -214,3 +214,3 @@ before(async function () {

type Mutation {
createBook(input: [Int] @constraint(maxItems: 2)): Book
createBook(input: [Int] @constraint(maxItems: 2, max: 100)): Book
}`

@@ -266,2 +266,3 @@

isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 1)
strictEqual(

@@ -274,5 +275,161 @@ body.errors[0].message,

})
it('should fail - another scalar validation', async function () {
const query = `mutation createBook {
createBook(input: [2, 101]) {
title
}
}`
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query })
isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 1)
strictEqual(
body.errors[0].message,
'Argument "input" of "createBook" got invalid value 101 at "[1]"' +
valueByImplType(implType, '; Expected type "title_List_Int_NotNull_max_3"') +
'. Must be no greater than 100'
)
})
})
})
describe('Scalar argument of ID type', function () {
describe('#minItems', function () {
before(async function () {
this.typeDefs = `
type Query {
books: [Book]
}
type Book {
title: String
}
type Mutation {
createBook(input: [ID]! @constraint(minItems: 3)): Book
}`
this.request = await setup(this.typeDefs)
})
it('should pass', async function () {
const query = `mutation createBook {
createBook(input: ["2","3","4"]) {
title
}
}`
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query })
strictEqual(statusCode, 200)
deepStrictEqual(body, { data: { createBook: null } })
})
it('should fail', async function () {
const query = `mutation createBook {
createBook(input: ["2","3"]) {
title
}
}`
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query })
isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 1)
strictEqual(
body.errors[0].message,
'Argument "input" of "createBook"' +
valueByImplType(implType, '; Expected type "title_List_ListNotNull_Int_NotNull_min_3"') +
' must be at least 3 in length'
)
})
})
})
describe('InputObject argument', function () {
describe('#minItems', function () {
before(async function () {
this.typeDefs = `
type Query {
books: [Book]
}
type Book {
title: String
}
type Mutation {
createBook(input: [BookInput]! @constraint(minItems: 3)): Book
}
input BookInput {
title: String @constraint(maxLength: 2)
}
`
this.request = await setup(this.typeDefs)
})
it('should pass', async function () {
const query = `mutation createBook {
createBook(input: [{title:"aa"},{title:"ab"},{title:"ba"}]) {
title
}
}`
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query })
strictEqual(statusCode, 200)
deepStrictEqual(body, { data: { createBook: null } })
})
it('should fail', async function () {
const query = `mutation createBook {
createBook(input: [{title:"aa"},{title:"ab"}]) {
title
}
}`
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query })
isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 1)
strictEqual(
body.errors[0].message,
'Argument "input" of "createBook"' +
valueByImplType(implType, '; Expected type "title_List_ListNotNull_Int_NotNull_min_3"') +
' must be at least 3 in length'
)
})
it('should fail - another validation in input object', async function () {
const query = `mutation createBook {
createBook(input: [{title:"aa"},{title:"abc"},{title:"as"}]) {
title
}
}`
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query })
isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 1)
strictEqual(
body.errors[0].message,
'Argument "input" of "createBook" got invalid value "abc" at "[1].title"' +
valueByImplType(implType, '; Expected type "title_List_ListNotNull_Int_NotNull_min_3"') +
'. Must be no more than 2 characters in length'
)
})
})
})
})
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc