graphql-platform
graphql-platform copied to clipboard
EnrichError not getting called when producing HC0018
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
- create custom
ActivityEnricher
and overrideEnrichError(IError error, Activity activity)
. - register custom enricher
.AddSingleton<ActivityEnricher, CustomActivityEnricher>();
- produce HC0018 error
.AddQueryType(d => d
.Field("foo")
.Type<NonNullType<StringType>>()
.Resolve((_, _) => null))
-
EnrichError
is not getting called nor theEnrichHttpRequestError
(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
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.
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
});
This one is fixed!
@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.