Skip to content

Instantly share code, notes, and snippets.

@aSemy
Last active May 30, 2018 15:17
Show Gist options
  • Save aSemy/0a4771eebebc8f202ad6c94c23c565ec to your computer and use it in GitHub Desktop.
Save aSemy/0a4771eebebc8f202ad6c94c23c565ec to your computer and use it in GitHub Desktop.
@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