2

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 Answer 1

7

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.