dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

bug: scalar coercing exceptions don't use typed graphql error

Open Meemaw opened this issue 1 year ago • 1 comments

Expected behavior

TypedGraphQLError is used consistently across all error surfaces.

Actual behavior

When using custom scalar, coercing exceptions (e.g CoercingParseLiteralException) don't use the TypedGraphQLError and provide very bare-bones errors.

This was improved in 8.6.0 for some validation errors, but custom scalar coercing was missed.

Steps to reproduce

Note: A test case would be highly appreciated, but we understand that's not always possible

Meemaw avatar May 19 '24 18:05 Meemaw

Thanks for flagging this. We'll fix this behavior in the next release or two .

srinivasankavitha avatar May 19 '24 23:05 srinivasankavitha

@Meemaw, could you please the steps to reproduce this issue?

mrvaruntandon avatar Jul 08 '24 10:07 mrvaruntandon

@srinivasankavitha is this issue open for contribution?

mrvaruntandon avatar Jul 08 '24 10:07 mrvaruntandon

Yes, this has not been addressed yet.

srinivasankavitha avatar Jul 08 '24 11:07 srinivasankavitha

Hello @srinivasankavitha,

I tried to create a project to understand this issue.

I created a query returning a custom scaler. While returning a value for the query, the serialize() method of Coercing interface from my custom implementation was invoked. When I passed a value that would throw CoercingSerializeException. The response for such a query was:

{
  "errors": [
    {
      "message": "Can't serialize value (/ip) : Invalid IPv4 address",
      "path": [
        "ip"
      ],
      "extensions": {
        "errorType": "UNAVAILABLE",
        "errorDetail": "SERVICE_ERROR"
      }
    }
  ],
  "data": {
    "ip": null
  }
}

I did not see any logs in my console telling me that CoercingSerializeException has happened.

Could you tell me if the above description successfully reproduces this issue?

Also, could share what should be the expected response here and how is it related to TypedGraphQLError class?

mrvaruntandon avatar Jul 10 '24 08:07 mrvaruntandon

@Meemaw, could you please the steps to reproduce this issue?

@Meemaw could you please check the way I have tried to reproduce this issue? Also, could you tell me what would be the expected behaviour here?

mrvaruntandon avatar Jul 10 '24 17:07 mrvaruntandon

@mrvaruntandon - I believe you have the correct repro of the issue. The ask is to fill out the errorType/errorDetail to reflect something closer to the exception rather than our generic UNAVAILABLE error. The logic to handle translating graphql-java error to a TypedGraphQlError is here: https://github.com/Netflix/dgs-framework/blob/master/graphql-dgs/src/main/kotlin/com/netflix/graphql/dgs/internal/GraphQLJavaErrorInstrumentation.kt#L29, so we just need to handle the CoercingSerializeException here.

srinivasankavitha avatar Jul 17 '24 21:07 srinivasankavitha

Hey @srinivasankavitha,

Thank you for your guidance! I have tried to resolve this issue via https://github.com/Netflix/dgs-framework/pull/1970. Could you please take a look and provide your comments.

Thanks in advance!

mrvaruntandon avatar Jul 29 '24 17:07 mrvaruntandon