Hi!
I'm trying to implement UpperCase directive using HotChocolate
Here is example how it could be implemented in ApolloServer: https://www.apollographql.com/docs/graphql-tools/schema-directives.html#Uppercasing-strings
I feel that it could be done in Directive Middleware but can't figured it out
That's how I try to solve this task:
public class UpperCaseDirectiveType : DirectiveType<UpperCaseDirective>
{
protected override void Configure(IDirectiveTypeDescriptor<UpperCaseDirective> descriptor)
{
descriptor
.Name("uppercase")
.Location(DirectiveLocation.Field | DirectiveLocation.FieldDefinition)
.Middleware(next => context => Do(context, next));
}
private static async Task Do(IDirectiveContext context, DirectiveDelegate next)
{
await next(context);
var result = context.Result as string;
if (result != null)
{
result = result.ToUpper();
context.Result = result;
}
}
}
but after calling await next(context) I get context.Result = null.
I think it's key point to problem
The same behavior I have in StarWars example from https://github.com/ChilliCream/hotchocolate-aspnetcore
If I add required claims and query
{
search(text: "Han") {
__typename
}
}
I'm getting null as result
Looks like it's related to my issue
It should work.... just give me a second, I will try it with the aspnet example.
So, that is a bug.... but you can use a workaround.
You can also shortcircut the middleware and force a resolve like the following:
descriptor.Middleware(next => async context =>
{
context.Result = (await context.ResolveAsync<string>()).ToUpperInvariant();
});
But, it should have worked like you did it. I will issue a fix tonight.
Thank you for quick response, I'll wait for fix.
Fixed with #358
Most helpful comment
So, that is a bug.... but you can use a workaround.
You can also shortcircut the middleware and force a resolve like the following:
But, it should have worked like you did it. I will issue a fix tonight.