originalError not available in formatError
See original GitHub issueIssue Description
Hello,
I am using graphql-constraint-directive with apollo-server-express But in formatError, when I call error.originalError it always return undefined. Here my code:
const { constraintDirective, constraintDirectiveTypeDefs } = require('graphql-constraint-directive')
const express = require('express')
const { ApolloServer } = require('apollo-server-express')
const { makeExecutableSchema } = require('graphql-tools')
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")
}`
const schema = makeExecutableSchema({
typeDefs: [constraintDirectiveTypeDefs, typeDefs],
schemaTransforms: [constraintDirective()]
})
const formatError = function (error) {
if (error.originalError && error.originalError.code === 'ERR_GRAPHQL_CONSTRAINT_VALIDATION') {
// return a custom object
}
console.log(error);
return error
}
const app = express()
const server = new ApolloServer({ schema, formatError })
server.applyMiddleware({ app })
app.listen({ port: 3000 }, () =>
console.log(`🚀 Server ready at http://localhost:3000${server.graphqlPath}`)
);
Please help me how can I fix it.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Error handling - Apollo GraphQL Docs
The formatError function does not modify errors that are sent to Apollo Studio as part of usage reporting. See For Apollo Studio reporting....
Read more >Custom Error Object with Apollo Server - Stack Overflow
I'm having trouble because when I log error.code from within formatError it's not available. formatError: function (error) { console.
Read more >Unreasonably Opaque GraphQL Errors (non-Error thrown as ...
So, I have a fix that does not require making modifications to useRedwoodLogger or formatError. Essentially, what I think happened was, in 0.50....
Read more >apollo-error-converter - npm
There are no other projects in the npm registry using ... assign it to the formatError option in ApolloError constructor. new ApolloServer({.
Read more >Custom errors, extending Error - The Modern JavaScript Tutorial
Our function readUser(json) will not only read JSON, but check (“validate”) the data. If there are no required fields, or the format is ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I fixed returning my errors to the frontend by adding the following code:
How are you using it? The debugger or
console.log(util.inspect(error, {showHidden: true, depth: null}))
should show the details. From what I recall, either GraphQL or Apollo defines them as hidden properties so a simple console.log won’t show them.