Socket
Socket
Sign inDemoInstall

graphql-constraint-directive

Package Overview
Dependencies
8
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.2 to 5.0.0

apollo4.d.ts

2

index.js

@@ -150,3 +150,3 @@ const {

if (errors.length > 0) {
setResultAndStopExecution({ errors: errors.map(err => { return new GraphQLError(err.message, null, null, null, null, err, { code: err.code, field: err.fieldName, context: err.context, exception: err.originalError }) }) })
setResultAndStopExecution({ errors: errors.map(err => { return new GraphQLError(err.message, err, { code: err.code, field: err.fieldName, context: err.context, exception: err.originalError }) }) })
}

@@ -153,0 +153,0 @@ }

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

this.currentField = node
this.currentrFieldDef = this.currentTypeInfo.typeDef.getFields()[node.name.value]
// this if handles union type correctly
if (this.currentTypeInfo.typeDef.getFields) { this.currentrFieldDef = this.currentTypeInfo.typeDef.getFields()[node.name.value] }
if (this.currentrFieldDef) {

@@ -152,2 +154,4 @@ const newTypeDef = getNamedType(this.currentrFieldDef.type)

function validateScalarTypeValue (context, currentQueryField, typeDefWithDirective, valueTypeDef, value, variableName, argName, fieldNameForError, errMessageAt) {
if (!typeDefWithDirective.astNode) { return }
const directiveArgumentMap = getDirectiveValues(constraintDirectiveTypeDefsObj, typeDefWithDirective.astNode)

@@ -177,2 +181,4 @@

function validateInputTypeValue (context, inputObjectTypeDef, argName, variableName, value, currentField, parentNames) {
if (!inputObjectTypeDef.astNode) { return }
// use new visitor to traverse input object structure

@@ -185,2 +191,4 @@ const visitor = new InputObjectValidationVisitor(context, inputObjectTypeDef, argName, variableName, value, currentField, parentNames)

function validateArrayTypeValue (context, valueTypeDef, typeDefWithDirective, value, currentField, argName, variableName, iFieldNameFull) {
if (!typeDefWithDirective.astNode) { return }
let valueTypeDefArray = valueTypeDef.ofType

@@ -277,3 +285,3 @@

// nothing to validate
if (!value) return
if (!value && value !== '') return

@@ -280,0 +288,0 @@ validateScalarTypeValue(this.context, this.currentField, iFieldTypeDef, valueTypeDef, value, this.variableName, this.argName, iFieldNameFull, ` at "${iFieldNameFull}"`)

{
"name": "graphql-constraint-directive",
"version": "4.1.2",
"version": "5.0.0",
"description": "Validate GraphQL fields",

@@ -11,2 +11,3 @@ "main": "index.js",

"test-apollo-plugin": "standard && nyc --reporter=html --reporter=text --reporter=lcov mocha test/**/testsuite-apollo-plugin.js",
"test-apollo4-plugin": "standard && nyc --reporter=html --reporter=text --reporter=lcov mocha test/**/testsuite-apollo4-plugin.js",
"test-envelop-plugin": "standard && nyc --reporter=html --reporter=text --reporter=lcov mocha test/**/testsuite-envelop-plugin.js",

@@ -36,16 +37,16 @@ "test-validation-rule-express-graphql": "standard && nyc --reporter=html --reporter=text --reporter=lcov mocha test/**/testsuite-validation-rule-express-graphql.js"

"devDependencies": {
"apollo-server-express": "^3.6.3",
"coveralls": "^3.1.0",
"express": "^4.17.3",
"express-graphql": "^0.12.0",
"graphql": "^15.5.0",
"mocha": "^9.2.1",
"nyc": "^15.0.1",
"standard": "^16.0.4",
"supertest": "^6.2.2",
"@graphql-yoga/node": "^2.13.3"
"apollo-server-express": "3.11.1",
"@apollo/server": "4.3.2",
"coveralls": "3.1.1",
"express": "4.18.2",
"graphql": "16.6.0",
"mocha": "10.2.0",
"nyc": "15.1.0",
"standard": "16.0.4",
"supertest": "6.3.3",
"@graphql-yoga/node": "2.13.13"
},
"dependencies": {
"@graphql-tools/schema": "^8.3.2",
"@graphql-tools/utils": "^8.6.2",
"@graphql-tools/schema": "^9.0.0",
"@graphql-tools/utils": "^9.0.0",
"validator": "^13.6.0"

@@ -52,0 +53,0 @@ },

@@ -121,5 +121,5 @@ # graphql-constraint-directive

#### Apollo Server
#### Apollo 3 Server
As an [Apollo Server](https://www.apollographql.com/docs/apollo-server/) plugin
As an [Apollo 3 Server](https://www.apollographql.com/docs/apollo-server/v3) plugin

@@ -167,4 +167,103 @@ ```js

#### Apollo 4 Server
As an [Apollo 4 Server](https://www.apollographql.com/docs/apollo-server/v4) plugin
```js
const { createApollo4QueryValidationPlugin, constraintDirectiveTypeDefs } = require('graphql-constraint-directive/apollo4')
const express = require('express')
const { ApolloServer } = require('@apollo/server')
const { makeExecutableSchema } = require('@graphql-tools/schema')
const cors = require('cors')
const { json } = require('body-parser')
const typeDefs = `
type Query {
books: [Book]
}
type Book {
title: String
}
type Mutation {
createBook(input: BookInput): Book
}
input BookInput {
title: String! @constraint(minLength: 5, format: "email")
}`
let schema = makeExecutableSchema({
typeDefs: [constraintDirectiveTypeDefs, typeDefs],
})
const plugins = [
createApollo4QueryValidationPlugin({
schema
})
]
const app = express()
const server = new ApolloServer({
schema,
plugins
})
await server.start()
app.use(
'/',
cors(),
json(),
expressMiddleware(server)
)
```
#### Apollo 4 Subgraph server
There is a small change required to make the Apollo Server quickstart work when trying to build an [Apollo Subgraph Server](https://www.apollographql.com/docs/federation/building-supergraphs/subgraphs-apollo-server/).
We must use the `buildSubgraphSchema` function to build a schema that can be passed to an Apollo Gateway/supergraph, instead of `makeExecuteableSchema`. This uses `makeExecutableSchema` under the hood.
```ts
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { buildSubgraphSchema } from '@apollo/subgraph';
import { createApollo4QueryValidationPlugin, constraintDirectiveTypeDefsGql } from 'graphql-constraint-directive/apollo4';
const typeDefs = gql`
extend schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@shareable"])
type Query {
books: [Book]
}
type Book {
title: String
}
type Mutation {
createBook(input: BookInput): Book
}
input BookInput {
title: String! @constraint(minLength: 5, format: "email")
}
`;
const schema = buildSubgraphSchema({
typeDefs: [constraintDirectiveTypeDefsGql, typeDefs]
});
const plugins = [
createApollo4QueryValidationPlugin({
schema
})
]
const server = new ApolloServer({
schema,
plugins
});
await startStandaloneServer(server);
```
#### Express
*This implementation is untested now, as [`express-graphql` module](https://github.com/graphql/express-graphql) is not maintained anymore.*
As a [Validation rule](https://graphql.org/graphql-js/validation/) when query `variables` are available

@@ -313,7 +412,12 @@

#### Apollo Server
Throws a [`UserInputError`](https://www.apollographql.com/docs/apollo-server/data/errors/#bad_user_input) for each validation error
#### Apollo Server 3
Throws a [`UserInputError`](https://www.apollographql.com/docs/apollo-server/data/errors/#bad_user_input) for each validation error.
#### Apollo Server 4
Throws a prefilled `GraphQLError` with `extensions.code` set to `BAD_USER_INPUT` and http status code `400`.
In case of more validation errors, top level error is generic with `Query is invalid, for details see extensions.validationErrors` message,
detailed errors are stored in `extensions.validationErrors` of this error.
#### Envelop
The Envelop plugin throws a prefilled `GraphQLError` for each validation error
The Envelop plugin throws a prefilled `GraphQLError` for each validation error.

@@ -320,0 +424,0 @@ ### uniqueTypeName

const { deepStrictEqual, strictEqual } = require('assert')
const { formatError, valueByImplType, isSchemaWrapperImplType, isStatusCodeError } = require('./testutils')
const { formatError, valueByImplType, isSchemaWrapperImplType, isStatusCodeError, unwrapMoreValidationErrors } = require('./testutils')

@@ -47,3 +47,3 @@ module.exports.test = function (setup, implType) {

`
this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -77,2 +77,3 @@

// console.log('Body: ' + JSON.stringify(body))
isStatusCodeError(statusCode, implType)

@@ -102,5 +103,6 @@ strictEqual(body.errors[0].message,

isStatusCodeError(statusCode, implType)
strictEqual(body.errors[0].message,
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(errors[0].message,
'Variable "$size" got invalid value 4' + valueByImplType(implType, '; Expected type "size_Int_max_3"') + '. Must be no greater than 3')
strictEqual(body.errors[1].message,
strictEqual(errors[1].message,
'Variable "$sizeAuthors" got invalid value 5' + valueByImplType(implType, '; Expected type "size_Int_max_4"') + '. Must be no greater than 4')

@@ -111,3 +113,3 @@ })

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -190,3 +192,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -251,3 +253,4 @@

isStatusCodeError(statusCode, implType)
strictEqual(body.errors[0].message,
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(errors[0].message,
valueByImplType(implType,

@@ -257,3 +260,3 @@ 'Expected value of type "size_Int_NotNull_max_3!", found 100; Must be no greater than 3',

)
strictEqual(body.errors[1].message,
strictEqual(errors[1].message,
valueByImplType(implType,

@@ -267,3 +270,3 @@ 'Expected value of type "size_Int_max_4", found 5; Must be no greater than 4',

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -270,0 +273,0 @@ .post('/graphql')

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

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -90,3 +90,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -145,3 +145,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -218,3 +218,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -314,3 +314,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -373,3 +373,3 @@

`
this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -376,0 +376,0 @@

const { deepStrictEqual, strictEqual } = require('assert')
const { valueByImplType, isStatusCodeError } = require('./testutils')
const { valueByImplType, isStatusCodeError, unwrapMoreValidationErrors } = require('./testutils')

@@ -32,3 +32,3 @@ module.exports.test = function (setup, implType) {

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -83,3 +83,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -105,4 +105,5 @@

isStatusCodeError(statusCode, implType)
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(
body.errors[0].message,
errors[0].message,
'Variable "$input" got invalid value "asdsdd" at "input.authors[0].name"' +

@@ -113,3 +114,3 @@ valueByImplType(implType, '; Expected type "name_String_NotNull_maxLength_5"') +

strictEqual(
body.errors[1].message,
errors[1].message,
'Variable "$input" got invalid value 2 at "input.authors[0].age[1]"' +

@@ -120,3 +121,3 @@ valueByImplType(implType, '; Expected type "age_List_ListNotNull_Int_NotNull_min_3"') +

strictEqual(
body.errors[2].message,
errors[2].message,
'Variable "$input" got invalid value 1 at "input.authors[1].age[0]"' +

@@ -150,3 +151,3 @@ valueByImplType(implType, '; Expected type "age_List_ListNotNull_Int_NotNull_min_3"') +

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -186,4 +187,5 @@

isStatusCodeError(statusCode, implType)
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(
body.errors[0].message,
errors[0].message,
valueByImplType(implType, 'Expected value of type "name_String_NotNull_maxLength_5!", found "asdsdd";',

@@ -194,3 +196,3 @@ 'Argument "input" of "createBook" got invalid value "asdsdd" at "authors[0].name".') +

strictEqual(
body.errors[1].message,
errors[1].message,
valueByImplType(implType, 'Expected value of type "age_List_ListNotNull_Int_NotNull_min_3!", found 2;',

@@ -201,3 +203,3 @@ 'Argument "input" of "createBook" got invalid value 2 at "authors[0].age[1]".') +

strictEqual(
body.errors[2].message,
errors[2].message,
valueByImplType(implType, 'Expected value of type "age_List_ListNotNull_Int_NotNull_min_3!", found 1;',

@@ -233,3 +235,3 @@ 'Argument "input" of "createBook" got invalid value 1 at "authors[1].age[0]".') +

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -277,3 +279,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -344,3 +346,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -366,4 +368,5 @@

isStatusCodeError(statusCode, implType)
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(
body.errors[0].message,
errors[0].message,
'Variable "$input" got invalid value "asdfrs" at "input[0].title"' +

@@ -397,3 +400,3 @@ valueByImplType(implType, '; Expected type "title_String_NotNull_maxLength_5"') +

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -429,4 +432,5 @@

isStatusCodeError(statusCode, implType)
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(
body.errors[0].message,
errors[0].message,
valueByImplType(implType, 'Expected value of type "title_String_NotNull_maxLength_5!", found "asdfrs";',

@@ -433,0 +437,0 @@ 'Argument "input" of "createBook" got invalid value "asdfrs" at "[0].title".') +

const { deepStrictEqual, strictEqual } = require('assert')
const { valueByImplType, isServerValidatorRule, isServerValidatorEnvelop, isStatusCodeError } = require('./testutils')
const { valueByImplType, isServerValidatorRule, isServerValidatorEnvelop, isStatusCodeError, isServerValidatorApollo4 } = require('./testutils')

@@ -29,3 +29,3 @@ module.exports.test = function (setup, implType) {

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -74,3 +74,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -120,3 +120,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -131,3 +131,3 @@

if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { strictEqual(statusCode, 400) }
if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { isServerValidatorApollo4(implType) ? strictEqual(statusCode, 200) : strictEqual(statusCode, 400) }
strictEqual(

@@ -147,3 +147,3 @@ body.errors[0].message,

if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { strictEqual(statusCode, 400) }
if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { isServerValidatorApollo4(implType) ? strictEqual(statusCode, 200) : strictEqual(statusCode, 400) }
strictEqual(

@@ -182,3 +182,3 @@ body.errors[0].message,

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

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

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -274,3 +274,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -277,0 +277,0 @@

const { deepStrictEqual, strictEqual } = require('assert')
const { valueByImplType, formatError, isSchemaWrapperImplType, isServerValidatorRule, isServerValidatorEnvelop, isStatusCodeError } = require('./testutils')
const { valueByImplType, formatError, isSchemaWrapperImplType, isServerValidatorRule, isServerValidatorEnvelop, isStatusCodeError, isServerValidatorApollo4 } = require('./testutils')

@@ -29,3 +29,3 @@ module.exports.test = function (setup, implType) {

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -56,3 +56,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -90,3 +90,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -117,3 +117,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -151,3 +151,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -182,3 +182,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -216,3 +216,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -247,3 +247,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -281,3 +281,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -308,3 +308,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -342,3 +342,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -353,3 +353,3 @@

if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { strictEqual(statusCode, 400) }
if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { isServerValidatorApollo4(implType) ? strictEqual(statusCode, 200) : strictEqual(statusCode, 400) }
strictEqual(body.errors[0].message,

@@ -365,3 +365,3 @@ 'Variable "$input" got invalid value null at "input.title"; Expected non-nullable type "' + valueByImplType(implType, 'title_Float_NotNull_multipleOf_2', 'Float') + '!" not to be null.')

if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { strictEqual(statusCode, 400) }
if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { isServerValidatorApollo4(implType) ? strictEqual(statusCode, 200) : strictEqual(statusCode, 400) }
strictEqual(body.errors[0].message,

@@ -389,3 +389,3 @@ 'Variable "$input" got invalid value {}; Field "title" of required type "' + valueByImplType(implType, 'title_Float_NotNull_multipleOf_2', 'Float') + '!" was not provided.')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -430,3 +430,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -456,3 +456,3 @@ if (isSchemaWrapperImplType(implType)) {

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -506,3 +506,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -519,3 +519,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -532,3 +532,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -563,3 +563,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -576,3 +576,3 @@ .post('/graphql')

const mockData = [{ title: -1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -602,3 +602,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -615,3 +615,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -628,3 +628,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -659,3 +659,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: -2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -672,3 +672,3 @@ .post('/graphql')

const mockData = [{ title: -2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -698,3 +698,3 @@ .post('/graphql')

const mockData = [{ title: 3 }, { title: 4 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -711,3 +711,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -724,3 +724,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -755,3 +755,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 4 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -768,3 +768,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -794,3 +794,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: 1 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -807,3 +807,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -820,3 +820,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -851,3 +851,3 @@ .post('/graphql')

const mockData = [{ title: -1 }, { title: -2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -864,3 +864,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: -2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -890,3 +890,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 4 }, { title: 6 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -903,3 +903,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -916,3 +916,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -947,3 +947,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -960,3 +960,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -973,3 +973,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -976,0 +976,0 @@ .post('/graphql')

const { deepStrictEqual, strictEqual } = require('assert')
const { valueByImplType, isStatusCodeError } = require('./testutils')
const { valueByImplType, isStatusCodeError, unwrapMoreValidationErrors } = require('./testutils')

@@ -22,3 +22,3 @@ module.exports.test = function (setup, implType) {

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -74,4 +74,5 @@

isStatusCodeError(statusCode, implType)
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(
body.errors[0].message,
errors[0].message,
valueByImplType(implType, 'Expected value of type "max_Int_min_5", found 4;', 'Argument "max" of "authors" got invalid value 4.') +

@@ -81,3 +82,3 @@ ' Must be at least 5'

strictEqual(
body.errors[1].message,
errors[1].message,
valueByImplType(implType, 'Expected value of type "min_Int_min_4", found 3;', 'Argument "min" of "volume" got invalid value 3.') +

@@ -126,4 +127,5 @@ ' Must be at least 4'

isStatusCodeError(statusCode, implType)
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(
body.errors[0].message,
errors[0].message,
'Variable "$arg1" got invalid value 4' +

@@ -134,3 +136,3 @@ valueByImplType(implType, '; Expected type "max_Int_min_5"') +

strictEqual(
body.errors[1].message,
errors[1].message,
'Variable "$arg2" got invalid value 3' +

@@ -137,0 +139,0 @@ valueByImplType(implType, '; Expected type "min_Int_min_4"') +

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

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -20,0 +20,0 @@

const { deepStrictEqual, strictEqual } = require('assert')
const { valueByImplType, formatError, isSchemaWrapperImplType, isStatusCodeError } = require('./testutils')
const { valueByImplType, formatError, isSchemaWrapperImplType, isStatusCodeError, unwrapMoreValidationErrors } = require('./testutils')

@@ -26,3 +26,3 @@ module.exports.test = function (setup, implType) {

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -77,6 +77,7 @@

isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 2)
strictEqual(body.errors[0].message,
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(errors.length, 2)
strictEqual(errors[0].message,
'Variable "$input" got invalid value 2 at "input.title"' + valueByImplType(implType, '; Expected type "title_Int_NotNull_min_3"') + '. Must be at least 3')
strictEqual(body.errors[1].message,
strictEqual(errors[1].message,
'Variable "$input" got invalid value "a" at "input.author.name"' + valueByImplType(implType, '; Expected type "name_String_NotNull_minLength_2"') + '. Must be at least 2 characters in length')

@@ -87,3 +88,3 @@ })

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -160,4 +161,5 @@ .post('/graphql')

isStatusCodeError(statusCode, implType)
strictEqual(body.errors.length, 2)
strictEqual(body.errors[0].message,
const errors = unwrapMoreValidationErrors(body.errors)
strictEqual(errors.length, 2)
strictEqual(errors[0].message,
valueByImplType(implType,

@@ -167,3 +169,3 @@ 'Expected value of type "title_Int_NotNull_min_3!", found 2; Must be at least 3',

)
strictEqual(body.errors[1].message,
strictEqual(errors[1].message,
valueByImplType(implType,

@@ -177,3 +179,3 @@ 'Expected value of type "name_String_NotNull_minLength_2!", found "a"; Must be at least 2 characters in length',

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -180,0 +182,0 @@ .post('/graphql')

const { deepStrictEqual, strictEqual } = require('assert')
const { valueByImplType, formatError, isSchemaWrapperImplType, isServerValidatorRule, isServerValidatorEnvelop, isStatusCodeError } = require('./testutils')
const { valueByImplType, formatError, isSchemaWrapperImplType, isServerValidatorRule, isServerValidatorEnvelop, isStatusCodeError, isServerValidatorApollo4 } = require('./testutils')

@@ -28,3 +28,3 @@ module.exports.test = function (setup, implType) {

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -55,3 +55,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -89,3 +89,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -116,3 +116,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -150,3 +150,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -181,3 +181,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -215,3 +215,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -246,3 +246,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -280,3 +280,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -307,3 +307,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -341,3 +341,3 @@ .post('/graphql')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -352,3 +352,3 @@

if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { strictEqual(statusCode, 400) }
if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { isServerValidatorApollo4(implType) ? strictEqual(statusCode, 200) : strictEqual(statusCode, 400) }
strictEqual(body.errors[0].message,

@@ -364,3 +364,3 @@ 'Variable "$input" got invalid value null at "input.title"; Expected non-nullable type "' + valueByImplType(implType, 'title_Int_NotNull_multipleOf_2', 'Int') + '!" not to be null.')

if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { strictEqual(statusCode, 400) }
if (isServerValidatorRule(implType)) { strictEqual(statusCode, 500) } else { isServerValidatorApollo4(implType) ? strictEqual(statusCode, 200) : strictEqual(statusCode, 400) }
strictEqual(body.errors[0].message,

@@ -388,3 +388,3 @@ 'Variable "$input" got invalid value {}; Field "title" of required type "' + valueByImplType(implType, 'title_Int_NotNull_multipleOf_2', 'Int') + '!" was not provided.')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -429,3 +429,3 @@

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -456,3 +456,3 @@

it('should throw custom error', async function () {
const request = await setup(this.typeDefs, formatError)
const request = await setup({ typeDefs: this.typeDefs, formatError })
const { body, statusCode } = await request

@@ -506,3 +506,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -519,3 +519,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -532,3 +532,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -563,3 +563,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -576,3 +576,3 @@ .post('/graphql')

const mockData = [{ title: -1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -602,3 +602,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -615,3 +615,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -628,3 +628,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -659,3 +659,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: -2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -672,3 +672,3 @@ .post('/graphql')

const mockData = [{ title: -2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -698,3 +698,3 @@ .post('/graphql')

const mockData = [{ title: 3 }, { title: 4 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -711,3 +711,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -724,3 +724,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -755,3 +755,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 4 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -768,3 +768,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -794,3 +794,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: 1 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -807,3 +807,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -820,3 +820,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -851,3 +851,3 @@ .post('/graphql')

const mockData = [{ title: -1 }, { title: -2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -864,3 +864,3 @@ .post('/graphql')

const mockData = [{ title: 0 }, { title: -2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -890,3 +890,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 4 }, { title: 6 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -903,3 +903,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -916,3 +916,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -947,3 +947,3 @@ .post('/graphql')

const mockData = [{ title: 2 }, { title: 3 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -960,3 +960,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -973,3 +973,3 @@ .post('/graphql')

const mockData = [{ title: 1 }, { title: 2 }]
const request = await setup(this.typeDefs, formatError, resolvers(mockData))
const request = await setup({ typeDefs: this.typeDefs, formatError, resolvers: resolvers(mockData) })
const { body, statusCode } = await request

@@ -976,0 +976,0 @@ .post('/graphql')

@@ -23,3 +23,3 @@ const { strictEqual, notEqual } = require('assert')

this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -26,0 +26,0 @@

@@ -7,4 +7,4 @@ const express = require('express')

module.exports = async function (typeDefs, formatError, resolvers) {
const schema = makeExecutableSchema({
module.exports = async function ({ typeDefs, formatError, resolvers, schemaCreatedCallback }) {
let schema = makeExecutableSchema({
typeDefs: [constraintDirectiveTypeDefs, typeDefs],

@@ -14,2 +14,6 @@ resolvers

if (schemaCreatedCallback) {
schema = schemaCreatedCallback(schema)
}
const plugins = [

@@ -16,0 +20,0 @@ createApolloQueryValidationPlugin({

@@ -7,4 +7,4 @@ const express = require('express')

module.exports = async function (typeDefs, formatError, resolvers) {
const schema = makeExecutableSchema({
module.exports = async function ({ typeDefs, formatError, resolvers, schemaCreatedCallback }) {
let schema = makeExecutableSchema({
typeDefs: [constraintDirectiveTypeDefs, typeDefs],

@@ -14,2 +14,6 @@ resolvers

if (schemaCreatedCallback) {
schema = schemaCreatedCallback(schema)
}
const app = express()

@@ -16,0 +20,0 @@ const yoga = createServer({

@@ -7,3 +7,3 @@ const express = require('express')

module.exports = async function (typeDefs, formatError, resolvers) {
module.exports = async function ({ typeDefs, formatError, resolvers, schemaCreatedCallback }) {
let schema = makeExecutableSchema({

@@ -14,2 +14,6 @@ typeDefs: [constraintDirectiveTypeDefs, typeDefs],

if (schemaCreatedCallback) {
schema = schemaCreatedCallback(schema)
}
schema = constraintDirective()(schema)

@@ -16,0 +20,0 @@

@@ -7,4 +7,4 @@ const express = require('express')

module.exports = async function (typeDefs, formatError, resolvers) {
const schema = makeExecutableSchema({
module.exports = async function ({ typeDefs, formatError, resolvers, schemaCreatedCallback }) {
let schema = makeExecutableSchema({
typeDefs: [constraintDirectiveTypeDefs, typeDefs],

@@ -14,2 +14,6 @@ resolvers

if (schemaCreatedCallback) {
schema = schemaCreatedCallback(schema)
}
const app = express()

@@ -16,0 +20,0 @@

@@ -19,2 +19,4 @@ const setup = require('./setup-apollo-plugin')

require('./string.test').test(setup, IMPL_TYPE)
require('./argument-dynamic.test').test(setup, IMPL_TYPE)
require('./union.test').test(setup, IMPL_TYPE)
})

@@ -19,2 +19,4 @@ const setup = require('./setup-envelop-plugin')

require('./string.test').test(setup, IMPL_TYPE)
require('./argument-dynamic.test').test(setup, IMPL_TYPE)
require('./union.test').test(setup, IMPL_TYPE)
})
require('./testsuite-schema-wrapper')
require('./testsuite-apollo-plugin')
require('./testsuite-apollo4-plugin')
require('./testsuite-envelop-plugin')
require('./testsuite-validation-rule-express-graphql')
// require('./testsuite-validation-rule-express-graphql') // deprecated, may be removed later or rewritent to another server if available

@@ -18,2 +18,4 @@ const setup = require('./setup-schema-wrapper')

require('./string.test').test(setup, IMPL_TYPE)
require('./argument-dynamic.test').test(setup, IMPL_TYPE)
require('./union.test').test(setup, IMPL_TYPE)
})

@@ -19,2 +19,3 @@ const setup = require('./setup-validation-rule-express-graphql')

require('./string.test').test(setup, IMPL_TYPE)
require('./argument-dynamic.test').test(setup, IMPL_TYPE)
})

@@ -52,2 +52,12 @@ const { strictEqual } = require('assert')

/**
* Return true if implementation type is `IMPL_TYPE_SERVER_VALIDATOR_APOLLO4` - usefull for tests which need to vary based on implementation type.
*
* @param {*} implType to check
* @returns true if `implType` is `IMPL_TYPE_SERVER_VALIDATOR_APOLLO4`
*/
function isServerValidatorApollo4 (implType) {
return implType === IMPL_TYPE_SERVER_VALIDATOR_APOLLO4
}
/**
* Return true if implementation type is `IMPL_TYPE_SERVER_VALIDATOR_ENVELOP` - usefull for tests which need to vary based on implementation type.

@@ -72,3 +82,19 @@ *

/**
* Unwrap multiple validation errors, as some plugins wrap them into one error.
*
* @param {any[]} errors returned from query
* @returns {any[]} unwrapped error
*/
function unwrapMoreValidationErrors (errors) {
if (errors && errors.length === 1 && errors[0]?.extensions?.validationErrors) {
strictEqual(errors[0].message, 'Query is invalid, for details see extensions.validationErrors')
return errors[0].extensions.validationErrors
} else {
return errors
}
}
const IMPL_TYPE_SERVER_VALIDATOR_APOLLO = 'serverValidatorApollo'
const IMPL_TYPE_SERVER_VALIDATOR_APOLLO4 = 'serverValidatorApollo4'
const IMPL_TYPE_SERVER_VALIDATOR_ENVELOP = 'serverValidatorEnvelop'

@@ -81,2 +107,3 @@ const IMPL_TYPE_SERVER_VALIDATOR_RULE = 'serverValidatorRule'

IMPL_TYPE_SERVER_VALIDATOR_APOLLO,
IMPL_TYPE_SERVER_VALIDATOR_APOLLO4,
IMPL_TYPE_SERVER_VALIDATOR_ENVELOP,

@@ -88,5 +115,7 @@ IMPL_TYPE_SERVER_VALIDATOR_RULE,

isServerValidatorApollo,
isServerValidatorApollo4,
isServerValidatorEnvelop,
isServerValidatorRule,
formatError
formatError,
unwrapMoreValidationErrors
}

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

`
this.request = await setup(this.typeDefs)
this.request = await setup({ typeDefs: this.typeDefs })
})

@@ -21,0 +21,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc