Skip to content

Conversation

PHILLIPS71
Copy link
Contributor

Description

This PR adds support for binding open generic types to filter types in FilterConvention, addressing a limitation where you had to manually register every concrete generic type instance.

Problem

Previously, the BindRuntimeType method only supported exact type matches. For generic types like Id<T>, you were forced to bind each concrete implementation individually:

// before: required for every generic type instance
descriptor.BindRuntimeType<Id<User>, IdOperationFilterInput>();
descriptor.BindRuntimeType<Id<Product>, IdOperationFilterInput>();
descriptor.BindRuntimeType<Id<Order>, IdOperationFilterInput>();
// ... dozens more bindings

This was non-ergonomic and defeated the purpose of generic types in C#.

Solution

Enhanced the TryCreateFilterType method in FilterConvention to support open generic type bindings:

// after: single binding for all generic type instances
descriptor.BindRuntimeType(typeof(Id<>), typeof(IdOperationFilterInput));

The implementation directly addresses the core issue raised in #7082 - the inability to bind open generic types and the resulting need to manually register each concrete generic type instance.

@michaelstaib
Copy link
Member

We will look at this for version 16 as we are doing more work in the HotChocolate.Data area.

@michaelstaib michaelstaib added this to the HC-16.0.0 milestone Aug 28, 2025
@michaelstaib michaelstaib marked this pull request as draft August 28, 2025 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants