byme8 / ZeroQL

C# GraphQL client with Linq-like syntax
MIT License
278 stars 13 forks source link

QueryRequestAnalyzer throwing a Null exception #11

Closed DaveRMaltby closed 2 years ago

DaveRMaltby commented 2 years ago

This issue is obscuring another issue that I'm having that is preventing me from calling a Mutation of mine. The error that I'm receiving is: 4>CSC : warning AD0001: Analyzer 'ZeroQL.SourceGenerators.Analyzers.QueryRequestAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.

I started debugging the analyer and see the root cause here. At https://github.com/byme8/ZeroQL/blob/main/src/ZeroQL.SourceGenerators/Analyzers/QueryRequestAnalyzer.cs#L73 the ZeroQLRequestLikeContextResolver.Resolve method can return an Error in its Result<GraphQLSourceGenerationContext> instance, but the if condition following the Resolve call only checks for an ErrorWithData<Diagnostic>. Its else then gets called which assumes that there is no error and that requestContext is not null (but it is null). Therefore, an exception occurs at https://github.com/byme8/ZeroQL/blob/main/src/ZeroQL.SourceGenerators/Analyzers/QueryRequestAnalyzer.cs#L83 when trying to get the OperationQuery property.

As for the other error, I'm still trying to pin it down and will create an issue for that, if it isn't something that I'm doing wrong. Love this library by the way. Thanks.

byme8 commented 2 years ago

Checkout v2.1.1. Now it handles the case with the Error properly.