Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mercurius-validation

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mercurius-validation - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

2

bench/gateway-bench.js

@@ -25,3 +25,3 @@ 'use strict'

{
url: 'http://localhost:3000/graphql',
url: 'http://127.0.0.1:3000/graphql',
connections: 100,

@@ -28,0 +28,0 @@ title: '',

@@ -80,2 +80,2 @@ 'use strict'

app.listen(3002)
app.listen({ port: 3002 })

@@ -50,2 +50,2 @@ 'use strict'

app.listen(3001)
app.listen({ port: 3001 })

@@ -13,6 +13,6 @@ 'use strict'

name: 'user',
url: 'http://localhost:3001/graphql'
url: 'http://127.0.0.1:3001/graphql'
}, {
name: 'post',
url: 'http://localhost:3002/graphql'
url: 'http://127.0.0.1:3002/graphql'
}]

@@ -42,2 +42,2 @@ },

app.listen(3000)
app.listen({ port: 3000 })

@@ -12,6 +12,6 @@ 'use strict'

name: 'user',
url: 'http://localhost:3001/graphql'
url: 'http://127.0.0.1:3001/graphql'
}, {
name: 'post',
url: 'http://localhost:3002/graphql'
url: 'http://127.0.0.1:3002/graphql'
}]

@@ -23,2 +23,2 @@ },

app.listen(3000)
app.listen({ port: 3000 })

@@ -23,3 +23,3 @@ 'use strict'

{
url: 'http://localhost:3000/graphql',
url: 'http://127.0.0.1:3000/graphql',
connections: 100,

@@ -26,0 +26,0 @@ title: '',

@@ -44,2 +44,2 @@ 'use strict'

app.listen(3000)
app.listen({ port: 3000 })

@@ -16,2 +16,2 @@ 'use strict'

app.listen(3000)
app.listen({ port: 3000 })

@@ -55,3 +55,3 @@ # Registration

app.listen(3000)
app.listen({ port: 3000 })
```

@@ -63,2 +63,2 @@ 'use strict'

app.listen(3000)
app.listen({ port: 3000 })

@@ -14,3 +14,3 @@ 'use strict'

})
await service.listen(0)
await service.listen({ port: 0 })
return [service, service.server.address().port]

@@ -126,6 +126,6 @@ }

name: 'user',
url: `http://localhost:${userServicePort}/graphql`
url: `http://127.0.0.1:${userServicePort}/graphql`
}, {
name: 'post',
url: `http://localhost:${postServicePort}/graphql`
url: `http://127.0.0.1:${postServicePort}/graphql`
}]

@@ -153,5 +153,5 @@ }

await gateway.listen(3000)
await gateway.listen({ port: 3000 })
}
start()

@@ -81,2 +81,2 @@ 'use strict'

app.listen(3000)
app.listen({ port: 3000 })

@@ -82,2 +82,2 @@ 'use strict'

app.listen(3000)
app.listen({ port: 3000 })

@@ -25,3 +25,3 @@ 'use strict'

name: 'mercurius-validation',
fastify: '>=3.x',
fastify: '4.x',
dependencies: ['mercurius']

@@ -28,0 +28,0 @@ }

@@ -15,2 +15,3 @@ 'use strict'

}
this.statusCode = 400
ValidationError.prototype[Symbol.toStringTag] = 'Error'

@@ -17,0 +18,0 @@ ValidationError.prototype.toString = function () {

{
"name": "mercurius-validation",
"version": "2.0.2",
"version": "3.0.0",
"description": "Mercurius Validation Plugin adds configurable Validation support to Mercurius.",

@@ -37,21 +37,21 @@ "main": "index.js",

"devDependencies": {
"@sinonjs/fake-timers": "^9.0.0",
"@types/node": "^17.0.0",
"@types/ws": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"autocannon": "^7.0.5",
"concurrently": "^7.0.0",
"fastify": "^3.0.2",
"mercurius": "^9.1.0",
"@sinonjs/fake-timers": "^9.1.2",
"@types/node": "^18.0.0",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.30.3",
"@typescript-eslint/parser": "^5.30.3",
"autocannon": "^7.9.0",
"concurrently": "^7.2.2",
"fastify": "^4.2.0",
"mercurius": "^10.0.0",
"pre-commit": "^1.2.2",
"snazzy": "^9.0.0",
"standard": "^17.0.0",
"tap": "^16.0.0",
"tsd": "^0.20.0",
"typescript": "^4.0.3",
"wait-on": "^6.0.0"
"tap": "^16.3.0",
"tsd": "^0.22.0",
"typescript": "^4.7.4",
"wait-on": "^6.0.1"
},
"dependencies": {
"@fastify/error": "^2.0.0",
"@fastify/error": "^3.0.0",
"ajv": "^8.6.2",

@@ -58,0 +58,0 @@ "ajv-errors": "^3.0.0",

@@ -120,3 +120,3 @@ # mercurius-validation

app.listen(3000)
app.listen({ port: 3000 })
```

@@ -191,3 +191,3 @@

app.listen(3000)
app.listen({ port: 3000 })
```

@@ -202,3 +202,3 @@

```text
Running 10s test @ http://localhost:3000/graphql
Running 10s test @ http://127.0.0.1:3000/graphql
100 connections

@@ -229,3 +229,3 @@

```text
Running 10s test @ http://localhost:3000/graphql
Running 10s test @ http://127.0.0.1:3000/graphql
100 connections

@@ -256,3 +256,3 @@

```text
Running 10s test @ http://localhost:3000/graphql
Running 10s test @ http://127.0.0.1:3000/graphql
100 connections

@@ -283,3 +283,3 @@

```text
Running 10s test @ http://localhost:3000/graphql
Running 10s test @ http://127.0.0.1:3000/graphql
100 connections

@@ -286,0 +286,0 @@

@@ -5,5 +5,37 @@ 'use strict'

const errors = require('../lib/errors')
const Fastify = require('fastify')
const mercurius = require('mercurius')
const mercuriusValidation = require('..')
const schema = `
${mercuriusValidation.graphQLTypeDefs}
type Message {
id: ID!
text: String
}
type Query {
# the result type must be non-nullable for the statusCode from the
# validation error to be propogated. If the result type is nullable
# then the graphql library does error protection which results in a
# status code of 200 ignoring the statusCode on the error:
messageNotNullable(id: ID @constraint(type: "string" format: "uuid")): Message!
messageNullable(id: ID @constraint(type: "string" format: "uuid")): Message
}
`
const resolvers = {
Query: {
messageNotNullable: async (_, { id }) => ({
id: 0,
text: 'Some system message.'
}),
messageNullable: async (_, { id }) => null
}
}
t.test('errors', t => {
t.plan(1)
t.plan(3)

@@ -17,3 +49,3 @@ t.test('MER_VALIDATION_ERR_FAILED_VALIDATION', t => {

t.test('should print a validation error to string', t => {
t.plan(1)
t.plan(2)

@@ -23,5 +55,140 @@ const error = new errors.MER_VALIDATION_ERR_FAILED_VALIDATION('some message', [])

t.same(error.toString(), 'ValidationError [MER_VALIDATION_ERR_FAILED_VALIDATION]: some message')
t.equal(error.statusCode, 400)
})
})
})
t.test('Validation errors result in a response status code of 400 when result is not nullable', async (t) => {
t.plan(2)
const app = Fastify()
t.teardown(app.close.bind(app))
app.register(mercurius, {
schema,
resolvers
})
app.register(mercuriusValidation)
const query = `query {
messageNotNullable(id: "") {
id
text
}
}`
const response = await app.inject({
method: 'POST',
headers: { 'content-type': 'application/json' },
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(JSON.parse(response.body), {
data: null,
errors: [
{
message: 'Failed Validation on arguments for field \'Query.messageNotNullable\'',
locations: [{
line: 2,
column: 7
}],
path: [
'messageNotNullable'
],
extensions: {
code: 'MER_VALIDATION_ERR_FAILED_VALIDATION',
name: 'ValidationError',
details: [
{
instancePath: '/id',
schemaPath: '#/properties/id/format',
keyword: 'format',
params: {
format: 'uuid'
},
message: 'must match format "uuid"',
schema: 'uuid',
parentSchema: {
$id: 'https://mercurius.dev/validation/Query/messageNotNullable/id',
type: 'string',
format: 'uuid'
},
data: ''
}
]
}
}
]
})
t.equal(response.statusCode, 400)
})
t.test('Validation errors result in a response status code of 200 when result is nullable', async (t) => {
t.plan(2)
const app = Fastify()
t.teardown(app.close.bind(app))
app.register(mercurius, {
schema,
resolvers
})
app.register(mercuriusValidation)
const query = `query {
messageNullable(id: "") {
id
text
}
}`
const response = await app.inject({
method: 'POST',
headers: { 'content-type': 'application/json' },
url: '/graphql',
body: JSON.stringify({ query })
})
t.same(JSON.parse(response.body), {
data: {
messageNullable: null
},
errors: [
{
message: 'Failed Validation on arguments for field \'Query.messageNullable\'',
locations: [{
line: 2,
column: 7
}],
path: [
'messageNullable'
],
extensions: {
code: 'MER_VALIDATION_ERR_FAILED_VALIDATION',
name: 'ValidationError',
details: [
{
instancePath: '/id',
schemaPath: '#/properties/id/format',
keyword: 'format',
params: {
format: 'uuid'
},
message: 'must match format "uuid"',
schema: 'uuid',
parentSchema: {
$id: 'https://mercurius.dev/validation/Query/messageNullable/id',
type: 'string',
format: 'uuid'
},
data: ''
}
]
}
}
]
})
t.equal(response.statusCode, 200)
})
})

@@ -15,3 +15,3 @@ 'use strict'

})
await service.listen(0)
await service.listen({ port: 0 })
return [service, service.server.address().port]

@@ -143,6 +143,6 @@ }

name: 'user',
url: `http://localhost:${userServicePort}/graphql`
url: `http://127.0.0.1:${userServicePort}/graphql`
}, {
name: 'post',
url: `http://localhost:${postServicePort}/graphql`
url: `http://127.0.0.1:${postServicePort}/graphql`
}]

@@ -149,0 +149,0 @@ }

@@ -86,3 +86,3 @@ 'use strict'

await messageService.listen(0)
await messageService.listen({ port: 0 })

@@ -96,3 +96,3 @@ const messageServicePort = messageService.server.address().port

name: 'message',
url: `http://localhost:${messageServicePort}/graphql`
url: `http://127.0.0.1:${messageServicePort}/graphql`
}

@@ -99,0 +99,0 @@ ],

Sorry, the diff of this file is not supported yet

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