graphql-platform
graphql-platform copied to clipboard
DataLoader source generation could be improved when used in business layer
Product
Hot Chocolate
Is your feature request related to a problem?
I'm trying out the source generator for data loaders in our project, where our data loaders live in the business layer and are used in MediatR requests.
I've found a few issues.
- The
DataLoaderAttributeandDataLoaderDefaultsAttributelive inHotChocolate.Abstractionsand notGreenDonutwhich requires adding a dependency to more HotChocolate specific things from a layer that doesn't really know anything about graphql. - Even though
GenerateRegistrationCodeis set to false, a using statement forusing HotChocolate.Execution.Configuration;is added to the top of the generated file, which requires another package reference to work. - Again, even though
GenerateRegistrationCodeis set to false, it generates theHotChocolateTypeModule.g.csfile with registrations, also with ausing HotChocolate.Execution.Configuration;statement - Data loader method signatures require the use of
IReadOnlyList<T>, otherwise it becomes aCacheDataLoader. In our codebase we generally use the less specificIEnumerable<T>, so it's very easy to end up with a different data loader than you expect. Similarly, it requires the return type to beIReadOnlyDictionary<,>and can't handle the less specificIDictionary<,> - Nullability doesn't seem to flow through correctly. If the return type of the method is
IReadOnlyDictionary<int, SomeType?>it generates it asIReadOnlyDictionary<int, SomeType>. This results in calls to.LoadAsyncnot having the potential to be null, which doesn't reflect the real world.
The solution you'd like
The ability to use the DataLoader source generator more independent from anything directly HotChocolate related (In projects that only reference GreenDonut).
If possible it would also be great if the source generator lived in a GreenDonut.Analyzers package instead.