Make `TryInferSchemaType` on `IDescriptorContext` public for use in custom type discovery handlers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp, graphql
- Domain
- backend-api-design
Research direction
Read src/HotChocolate/Core/src/Types/Configuration/TypeDiscoveryDescriptorContextExtensions.cs and inspect how IDescriptorContext exposes type-discovery APIs. Make TryInferSchemaType and TryInferSchemaTypeKind publicly available with an appropriate namespace, then verify the change against the existing type-discovery tests and public API checks; done means custom handlers can call the methods without duplicating handler dispatch and the existing inference behavior remains unchanged.
Written by the indexing model from the issue text.
Description
Product
Hot Chocolate
Is your feature request related to a problem?
A custom TypeDiscoveryHandler sometimes needs to know what schema type another runtime type would be inferred as, in order to decide on its own result.
Our case: we have a generic scalar WildcardOrType<TInner, TInnerScalar> for a WildcardOr<T> runtime type, which wraps whatever scalar T maps to (WildcardOr<FlagField<SomePrivilege>> → WildcardOrType<FlagField<SomePrivilege>, FlagFieldType<SomePrivilege>>, WildcardOr<string> → WildcardOrType<string, StringType>, etc.). To pick TInnerScalar, the handler for WildcardOr<T> needs to ask "what would T be inferred as?" — and the answer may come from any handler, custom (another of ours, e.g. the one for FlagField<T>) or built-in (ScalarTypeDiscoveryHandler).
TypeDiscoveryDescriptorContextExtensions.TryInferSchemaType does exactly this, but it's internal:
https://github.com/ChilliCream/graphql-platform/blob/16.6.8/src/HotChocolate/Core/src/Types/Configuration/TypeDiscoveryDescriptorContextExtensions.cs
So we've had to replicate it on top of the (public) IDescriptorContext.GetTypeDiscoveryHandlers():
var typeRef = context.TypeInspector.GetTypeRef(runtimeType, typeContext);
var typeInfo = new TypeDiscoveryInfo(typeRef);
foreach (var handler in context.GetTypeDiscoveryHandlers())
{
if (handler.TryInferType(typeRef, typeInfo, out var schemaTypeRefs))
return schemaTypeRefs;
}
return null;
It's short, but it duplicates framework logic and would silently diverge if the way handlers are consulted ever changes.
The solution you'd like
Make TryInferSchemaType (and, for symmetry, TryInferSchemaTypeKind) on IDescriptorContext public — e.g. by moving TypeDiscoveryDescriptorContextExtensions out of internal, possibly into the HotChocolate.Internal namespace alongside TypeDiscoveryHandler and TypeDiscoveryInfo, if it shouldn't be considered fully public API.
This would let type discovery handlers that are generic over another type compose with all other handlers instead of re-implementing the dispatch.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 14h 55m
- Merged PRs (30d)
- 208
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ChilliCream/graphql-platform
-
🌶️ hot chocolate
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
ChilliCream/graphql-platform#10567 ·
Maintainers usually reply within 1 day
-
QueryContext<T>.Sorting drops expression-based sort fieldsMay be free again A pull request for this issue was closed without being merged. Open🌶️ hot chocolate
Difficulty 3/5 1-2 days Newbie friendliness 48/100
ChilliCream/graphql-platform#10754 ·
Maintainers usually reply within 1 day
-
HC16: @defer with incremental delivery v0.1 exposes a lifetime race that can cause persistent high CPUPossibly taken @michaelstaib claimed this today. Open🌶️ hot chocolate
ChilliCream/graphql-platform#10668 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
🌶️ strawberry shake
Difficulty 5/5 Over a week Newbie friendliness 35/100
ChilliCream/graphql-platform#10643 ·
Maintainers usually reply within 1 day
-
🌶️ strawberry shake
Difficulty 3/5 1-2 days Newbie friendliness 76/100
ChilliCream/graphql-platform#10570 ·
Maintainers usually reply within 1 day
All issues in ChilliCream/graphql-platform
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
area: core priority: low type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
RicoSuter/Namotion.Interceptor#863 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitfoundation/bitplatform#14428 · 1 comment ·
Maintainers usually reply within 1 day
-
area-cli
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
0.3.0
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day