ChilliCream / ChilliCream/graphql-platform
Support QueryContext on ReferenceResolver for ApolloFederation
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Product
Hot Chocolate
Is your feature request related to a problem?
When using HotChocolate w/ ApolloFederation, if you try to add QueryContext as a parameter on a [ReferenceResolver] method, you get the following error when attempting to run a GraphQL query:
"extensions": {
"exception": {
"message": "No coercion operator is defined between types 'Subgraph.Entities.Employee' and 'Subgraph.Entities.EmployeeRelationshipEntity'.",
"stackTrace": "at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildTypeSwitchExpression(Context context, TypeContainer parent)
at HotChocolate.Execution.Projections.SelectionExpressionBuilder.BuildExpression[TRoot](Selection selection, UInt64 includeFlags)
at HotChocolate.Execution.Processing.<HotChocolateExecutionSelectionExtensions>FF70158D876F3061FDDBB9D1E7EDB0A5464CC82CDD650DA68B6E6D0205F91AFC7__Extensions.<>c__DisplayClass2_0`1.<GetOrCreateExpression>b__0()
at HotChocolate.Execution.Processing.OperationFeatureCollection.GetOrSetSafe[TFeature](Int32 selectionId, Func`1 factory)
at HotChocolate.Execution.Processing.SelectionFeatureCollection.GetOrSetSafe[TFeature](Func`1 factory)\r\n at HotChocolate.Execution.Processing.<HotChocolateExecutionSelectionExtensions>FF70158D876F3061FDDBB9D1E7EDB0A5464CC82CDD650DA68B6E6D0205F91AFC7__Extensions.GetOrCreateExpression[TValue](Selection selection)
at HotChocolate.Execution.Processing.HotChocolateExecutionSelectionExtensions.AsSelector[TValue](Selection selection, UInt64 includeFlags)
at HotChocolate.Data.QueryContextParameterExpressionBuilder.CreateQueryContext[T](IResolverContext context)
at lambda_method13(Closure, IResolverContext)
at HotChocolate.ApolloFederation.Resolvers.EntitiesResolver.ResolveEntityInternalAsync(FieldResolverDelegate resolver, IResolverContext context, ObjectType type, IValueNode representation)"
},
"service": "subgraph1"
}
The solution you'd like
I would like my reference resolvers to be able to take in the projected columns and pass that along to the data loader. If this is at all possible with ApolloFederation.
Example:
[ReferenceResolver]
public static async Task<Employee?> ResolveEmployee(int empId, QueryContext<Employee> query, IEmployeesByIdsDataLoader dataLoader, CancellationToken ct)
{
return await dataLoader.With(query).LoadAsync(empId, ct);
}
If I am doing this wrong currently, please advise me on the solution. Thank you.
Contributor 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.
Research direction
Start with the ReferenceResolver path and the QueryContextParameterExpressionBuilder entry shown in the stack trace. Reproduce the Apollo Federation query using the supplied resolver example, then trace how projected columns reach the data loader. Done means a reference resolver can accept QueryContext and pass it to the loader without the reported coercion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, graphql
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100