Graphql-Shield hijacks errors

423 views Asked by At

In the resolver throw new createError.BadRequest("bad input") error is hijacked by Graphql-shield and shown as

{
    "errors": [
        {
            "message": "Not Authorised!",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "myMutation"
            ],
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "exception": {
                    "stacktrace": [
                        "Error: Not Authorised!",

This is the Apollo Server setup

    const schema = buildSubgraphSchema([
      { typeDefs: await typeDefs(), resolvers },
    ]);
    const apolloServer = new ApolloServer({
      schema: applyMiddleware(schema, permissions),
      context: async ({ req, res }) => new AuthenticatedContext(req, res)
    });

How do I return the actual error occuring?

1

There are 1 answers

0
Fanature On

I found the solution on shield documentation:

const permissions = shield({
    Query: {
        ...
    },
    Mutation: {
        ...
    },
}, {allowExternalErrors: true});

The allowExternalErrors option is defaulted to be false according to the documentation.