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 1.1.0 to 1.2.0

scalars/formats/date.js

2

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

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

@@ -80,2 +80,3 @@ # graphql-constraint-directive

- date-time: RFC 3339
- date: ISO 8601
- email

@@ -82,0 +83,0 @@ - ipv4

@@ -7,3 +7,3 @@ const { GraphQLError } = require('graphql/error')

throw new GraphQLError('Must be a date in RFC 3339 format')
throw new GraphQLError('Must be a date-time in RFC 3339 format')
}
const formats = [
'byte',
'date-time',
'date',
'email',

@@ -5,0 +6,0 @@ 'ipv4',

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

strictEqual(body.errors[0].message,
'Variable "$input" got invalid value {"title":"a"}; Expected type ConstraintString at value.title; Must be a date in RFC 3339 format')
'Variable "$input" got invalid value {"title":"a"}; Expected type ConstraintString at value.title; Must be a date-time in RFC 3339 format')
})

@@ -544,3 +544,3 @@

deepStrictEqual(body.errors[0], {
message: 'Must be a date in RFC 3339 format',
message: 'Must be a date-time in RFC 3339 format',
code: 'ERR_GRAPHQL_CONSTRAINT_VALIDATION',

@@ -553,2 +553,63 @@ fieldName: 'title',

describe('#date', function () {
before(function () {
this.typeDefs = `
type Query {
books: [Book]
}
type Book {
title: String
}
type Mutation {
createBook(input: BookInput): Book
}
input BookInput {
title: String! @constraint(format: "date")
}`
this.request = setup(this.typeDefs)
})
it('should pass', async function () {
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({
query, variables: { input: { title: '2018-05-16' } }
})
strictEqual(statusCode, 200)
deepStrictEqual(body, { data: { createBook: null } })
})
it('should fail', async function () {
const { body, statusCode } = await this.request
.post('/graphql')
.set('Accept', 'application/json')
.send({
query, variables: { input: { title: 'a' } }
})
strictEqual(statusCode, 400)
strictEqual(body.errors[0].message,
'Variable "$input" got invalid value {"title":"a"}; Expected type ConstraintString at value.title; Must be a date in ISO 8601 format')
})
it('should throw custom error', async function () {
const request = setup(this.typeDefs, formatError)
const { body, statusCode } = await request
.post('/graphql')
.set('Accept', 'application/json')
.send({ query, variables: { input: { title: 'a' } } })
strictEqual(statusCode, 400)
deepStrictEqual(body.errors[0], {
message: 'Must be a date in ISO 8601 format',
code: 'ERR_GRAPHQL_CONSTRAINT_VALIDATION',
fieldName: 'title',
context: [{ arg: 'format', value: 'date' }]
})
})
})
describe('#email', function () {

@@ -555,0 +616,0 @@ before(function () {

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