How to validate fields of @GraphQLArgument ?
See original GitHub issueHello,
This is fantastic library but is not well documented…
I’d like ot know if it possible to validate fields af a type used as GrapQLArgument…
I have the service AuthService with the method
@GraphQLMutation(name = "create")
public User createUser(@GraphQLArgument(name = "userRequest") UserRequest userRequest) throws ServiceException {
User user = new User();
user = mapUser(user, userRequest);
return userDAO.store(user);
}
Then the Class UserRequest
public class UserRequest {
@GraphQLQuery(name = "name")
@NotEmpty(groups = CreateChecks.class)
private String name;
@GraphQLQuery(name = "surname")
@NotEmpty(groups = CreateChecks.class)
private String surname;
I sent the JSON
{
"query": "mutation ($userRequest : UserRequestInput!) { create(userRequest: $userRequest) { name } } ",
"params": {
"userRequest" :
{ "name" : "Name" }
}
}
I’d like that if change
@GraphQLQuery(name = "surname")
@GraphQLNonNuLL
@NotEmpty(groups = CreateChecks.class)
private String surname;
Then the method createUser was not called as the suname is missing and returns an error… Is it possible do something like that ?? How ?? I miss documentation on this things
Is it possibkle to create validationGroups as in REST with GraphQL ??
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
GraphQL validation using directives
A simple example: User sign up form. To see how schema validation could be used, it's easiest to start with an example.
Read more >graphql.validation.ValidationContext java code examples
graphql.validation. Best Java code snippets using graphql.validation. ... (fieldDef == null) return; Map<String, Argument> argumentMap = argumentMap(field.
Read more >Argument and Input validation - TypeGraphQL
Scalars. The standard way to ensure that inputs and arguments are correct, such as an email field that really contains a proper e-mail...
Read more >validator - Go Packages
type FieldArgumentRule interface { CheckFieldArgument( ctx *ValidationContext, field *FieldInfo, argDef *graphql.Argument, arg *ast.
Read more >GraphQL : Query failed to validate - Stack Overflow
So you don't need to further define what of its fields to be returned as the scalar does not have any fields for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you use Spring Framework, you can write:
If you try to create the entity with
you will get an error message like
Yes it works!
Install a ValidationModule in GUICE, then annotated the services with @ValidateOnExecution and you can use any validation on methods (including validation groups, custom validation, etc…)