You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And then in a class that implements SchemaDirectiveWiring
we should be able to modify the input object so that when it reaches the mutation method, the roomCode string would be all transformed to uppercase.
@DgsMutation
public JoinRoom joinRoom(@InputArgument JoinRoomInput joinRoomInput) {
Describe Preferred Solution
Right now we can transform a field in an output type by doing something like this
@Override
public GraphQLFieldDefinition onField(SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition> env )
{
GraphQLFieldDefinition field = env.getElement();
GraphQLFieldsContainer parentType = env.getFieldsContainer();
if (field.getDirective("stringCase") != null) {
GraphQLArgument argument = field.getDirective("stringCase").getArgument("case");
String argumentValue = ((EnumValue)argument.getArgumentValue().getValue()).getName();
// build a data fetcher that transforms the given value to uppercase/lowercase
DataFetcher originalFetcher = env.getCodeRegistry().getDataFetcher(parentType, field);
DataFetcher dataFetcher = DataFetcherFactories.wrapDataFetcher(originalFetcher, ((dataFetchingEnvironment, value) -> {
if (value instanceof String) {
if (argumentValue.equalsIgnoreCase("UPPER")) {
return ((String) value).toUpperCase();
}
if (argumentValue.equalsIgnoreCase("LOWER")) {
return ((String) value).toLowerCase();
}
}
return value;
}));
// now change the field definition to use the new uppercase/lowercase data fetcher
env.getCodeRegistry().dataFetcher(parentType, field, dataFetcher);
}
return field;
}
We should allow an input to be modified as well before it reaches the java mutation method.
The text was updated successfully, but these errors were encountered:
Did anyone post an example of custom directive implementation on the input fields specifically. The issue is closed but I don’t see such example in the official docs. I am having hard time figuring it out. All the examples out there override data fetcher but that won’t be the case with input fields.
Describe the Feature Request
I would like to be able to apply a @uppercase directive on a input string like so
And then in a class that implements SchemaDirectiveWiring
we should be able to modify the input object so that when it reaches the mutation method, the roomCode string would be all transformed to uppercase.
@DgsMutation
public JoinRoom joinRoom(@InputArgument JoinRoomInput joinRoomInput) {
Describe Preferred Solution
Right now we can transform a field in an output type by doing something like this
We should allow an input to be modified as well before it reaches the java mutation method.
The text was updated successfully, but these errors were encountered: