graphql-compose / graphql-compose/graphql-compose-mongoose
Validations are unable to return proper error messages with graphql v16
- Dominant language
- TypeScript
- Stars
- 706
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
I have started a new project, when I added `graphql` it installed version `^16.0.1`.
In my project I have a `mongoose.Schema` that validates an email string, the validation itself works, but when the mutation is given an invalid entry rather than returning the validation error message, I'm getting the following error:
```json
{
"errors": [
{
"message": "Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.",
"locations": [
{
"line": 7,
"column": 5
}
],
"path": [
"userCreateOne",
"error"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"message": "Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.",
"stacktrace": [
"GraphQLError: Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.",
" at ensureValidRuntimeType (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:816:11)",
" at completeAbstractValue (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:784:5)",
" at completeValue (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:612:12)",
" at executeField (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:477:19)",
" at executeFields (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:401:20)",
" at completeObjectValue (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:895:10)",
" at completeValue (./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:624:12)",
" at ./node_modules/.pnpm/graphql@16.0.1/node_modules/graphql/execution/execute.js:474:9",
" at processTicksAndRejections (internal/process/task_queues.js:95:5)",
" at execute (./node_modules/.pnpm/apollo-server-core@3.5.0_graphql@16.0.1/node_modules/apollo-server-core/src/requestPipeline.ts:485:14)"
]
}
}
}
],
"data": {
"userCreateOne": {
"recordId": null,
"record": null,
"error": null
}
}
}
```
If I downgrade `graphql` to `^15.5.0`, then I get a proper validation error message:
```json
{
"data": {
"userCreateOne": {
"recordId": null,
"record": null,
"error": {
"message": "User validation failed: email: Path `email` is invalid (example.com)."
}
}
}
}
```
I am guessing that the composed resolver returns a `GraphQLObjectType` as the `resolveType` when an error occurs, and as the error points out:
`Support for returning GraphQLObjectType from resolveType was removed in graphql-js@16.0.0 please return type name instead.`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.