Skip to content

Commit 4e8331c

Browse files
fix: yoga server not showing envelop extensions (#221)
1 parent b8b8cf3 commit 4e8331c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function createEnvelopQueryValidationPlugin (options = {}) {
228228
onExecute ({ args, setResultAndStopExecution }) {
229229
const errors = validateQuery(args.schema, args.document, args.variableValues, args.operationName, options)
230230
if (errors.length > 0) {
231-
setResultAndStopExecution({ errors: errors.map(err => { return new GraphQLError(err.message, err, { code: err.code, field: err.fieldName, context: err.context, exception: err.originalError }) }) })
231+
setResultAndStopExecution({ errors: errors.map(err => { return new GraphQLError(err.message, { extensions: { code: err.code, field: err.fieldName, context: err.context } }) }) })
232232
}
233233
}
234234
}

test/string.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ module.exports.test = function (setup, implType) {
147147
})
148148
})
149149
}
150+
151+
if (isServerValidatorEnvelop(implType)) {
152+
it('should throw custom error', async function () {
153+
const request = await setup({ typeDefs: this.typeDefs, formatError })
154+
const { body } = await request
155+
.post('/graphql')
156+
.set('Accept', 'application/json')
157+
.send({ query, variables: { input: { title: 'fob💩' } } })
158+
159+
deepStrictEqual(body, {
160+
errors: [
161+
{
162+
message: 'Variable "$input" got invalid value "fob💩" at "input.title". Must be no more than 3 characters in length',
163+
extensions: {
164+
code: 'ERR_GRAPHQL_CONSTRAINT_VALIDATION',
165+
field: 'input.title',
166+
context: [{ arg: 'maxLength', value: 3 }]
167+
}
168+
}
169+
]
170+
})
171+
})
172+
}
150173
})
151174

152175
describe('#startsWith', function () {

0 commit comments

Comments
 (0)