AWS AppSync schema validation errors not being passed to JS resolver

1

Hello Everyone,

I am working on an simple GraphQL API with some few different data sources(Dynamo, RDS, S3), we have a custom JS resolver to handle the errors from these different data sources, the idea is to give to my API users a consistent way to identify the different error types so they can show error in the UI accordingly. As described in the documentation here you can handle error having something like this in your response resolver

export function response(ctx) {
    const {error, result} = ctx;
    if (error) {
       // I don't know what triggers this append
        return util.appendError(error.message, error.type, result);
    } else if (result && result.errorMessage) {
        // handles custom errors coming from the data sources
        return util.error(result.errorMessage, result.errorType, result.data, result.errorInfo);
    } else {
        return result;
    }
}

This as expected, handles the errors coming from the data sources and produces a response that looks something like this

{
  "data": {
    "someMutation": null
  },
  "errors": [
    {
      "path": [
        "someMutation"
      ],
      "data": null,
      "errorType": "customErrorType",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Custom Error Message"
    }
  ]
}

Now the problem comes when the error is raised from the GraphQL schemas, for example:

mutation MyMutation {
  someMutation(payload: {email: "not-a-valid-email", name: "name"}) {
    id
  }
}

In this mutation the schema has the email defined as an AWSEmail so when this validation happen it never triggers the custom resolver so we ended with a response that looks pretty much like this

{
  "data": null,
  "errors": [
    {
      "path": null,
      "locations": [
        {
          "line": 2,
          "column": 16,
          "sourceName": null
        }
      ],
      "message": "Validation error of type WrongType: argument 'payload.email' with value 'StringValue{value='false'}' is not a valid 'AWSEmail' @ 'someMutation'"
    }
  ]
}

So as you can see the response is the default AppSync response without many details about what error type is being thrown by the API and it certainly never triggered the resolver we have in place.

So my question in specific is, Is there a way i can intercept ALL the errors coming from GraphQL, data sources, authentication, etc so i can output a consistent error response with enough information for my users?

Thanks

Luis
asked a month ago153 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions