graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

EnrichError not getting called when producing HC0018

Open glucaci opened this issue 2 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

EnrichError override not getting called when producing HC0018 error.

Steps to reproduce

  1. create custom ActivityEnricher and override EnrichError(IError error, Activity activity).
  2. register custom enricher
.AddSingleton<ActivityEnricher, CustomActivityEnricher>();
  1. produce HC0018 error
.AddQueryType(d => d
    .Field("foo")
    .Type<NonNullType<StringType>>()
    .Resolve((_, _) => null))
  1. EnrichError is not getting called nor the EnrichHttpRequestError (both overloads)

Relevant log output

{"errors":[{"message":"Cannot return null for non-nullable field.","locations":[{"line":1,"column":2}],"path":["foo"],"extensions":{"code":"HC0018"}}]}

Additional Context?

I'm getting the HttpClient response without getting into EnrichError.

In another use-case where I throw an Exception in the field resolver, the EnrichError is getting called.

Product

Hot Chocolate

Version

13.0.0-preview.9

glucaci avatar Mar 08 '22 12:03 glucaci

I've tried overriding all the methods on a custom enricher and none of them were called. It seems to be a broader issue. That is version 12.6.0 and 12.7.0.

queil avatar Mar 30 '22 11:03 queil

OK, so it looks like the issue is that the activity is null in here. Following this guidance I managed to get it working by adding the following code to my custom enricher constructor:

        ActivitySource.AddActivityListener(new ActivityListener
        {
             ShouldListenTo =  _ => true,
             SampleUsingParentId = (ref ActivityCreationOptions<string> activityOptions) 
                 => ActivitySamplingResult.AllData,
             Sample = (ref ActivityCreationOptions<ActivityContext> activityOptions) 
                 => ActivitySamplingResult.AllData
        });

queil avatar Mar 30 '22 13:03 queil

This one is fixed!

michaelstaib avatar Jan 18 '23 11:01 michaelstaib

@michaelstaib at least in my test this is not working. Just tested with 13.0.0-preview.103

new ServiceCollection()
    .AddSingleton<ActivityEnricher, GraphQLActivityEnricher>()
    .AddGraphQLServer()
    .AddQueryType(d => d
        .Field("foo")
        .Type<NonNullType<StringType>>()
        .Resolve((_, _) => null));

When the resolvers return null none of the Enrich*Error methods from the custom GraphQLActivityEnricher gets called.

glucaci avatar Jan 18 '23 15:01 glucaci