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
질문됨 2달 전157회 조회
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠