Last active
May 30, 2018 15:17
-
-
Save aSemy/0a4771eebebc8f202ad6c94c23c565ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class GraphQLRuleService { | |
// fetches messages from appropriate .prop file | |
@Autowired | |
private final MessagesService messagesService; | |
public RuleSingle stringNonBlank(final String argumentName, final String fieldName) { | |
return new RuleSingle() { | |
@Override | |
public Optional<GraphQLError> applySingle(FieldAndArguments fieldAndArguments, FieldValidationEnvironment environment) { | |
LinkedHashMap<String, String> arg = fieldAndArguments.getArgumentValue(argumentName); | |
String fieldValue = arg.get(fieldName); | |
if (StringUtils.isBlank(fieldValue)) | |
// the string is blank, so create an error | |
return Optional.of(environment.mkError(messagesService.getErrorBlankField(fieldName), fieldAndArguments)); | |
else | |
return Optional.empty(); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment