question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate FieldValidationInstrumentation

See original GitHub issue

graphql-java has recently implemented field level validation that is tested after the query is parsed, but before it is executed. https://github.com/graphql-java/graphql-java/issues/162

It would be really handy if this could be automatically generated using javax.validation annotations!

I’m only just starting my own implementation so I haven’t thought it through fully, but I can see it working as follows:

  1. In the method that generates a GraphQLSchema, also generate a FieldValidationInstrumentation
  2. This generate would, for each GraphQL query or mutation, check the arguments
  3. For each argument and fields of each argument get any javax.validation annotations
  4. Create a rule for each annotation. Add each rule to a SimpleFieldValidation
  5. The programmer could then add the FieldValidationInstrumentation to the GraphQL builder GraphQL.newGraphQL(...).instrumentation(instrumentation).build()

It would also be nice to have a custom org.springframework.validation.Validator bean that could check business logic (e.g. the email already exists in the database) but I haven’t thought about how that could be implemented yet.

There’s an example of the graphql-java validation in the method fieldValidation(), Line 161, shows an example.

https://github.com/graphql-java/graphql-java/blob/2f8f3de1d722ec0128b960c5e565405057fa76ff/src/test/groovy/readme/InstrumentationExamples.java#L161

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kdotzenrod517commented, Sep 17, 2020

Sorry if this is an old thread…I’m using JavaX validation constraints in my Spring app, how should I get SPQR to pick these up? Currently I have the below Object and am trying to validate this in my Graph query:

public class Example {
    @NotBlank
    @Pattern(regexp = ".{3,}")
    private String query;
}
  @GraphQLQuery(name = "exampleSearch")
  public List<String> searchList(@GraphQLArgument(name = "query") @RequestBody @Valid Example query) {
    return searchService.exampleSearch(query);
  }
0reactions
kaqqaocommented, Jul 31, 2019

@Matthias-Walter-Innio Answered your SO question as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating and Validating an Instrument - Statistics Solutions
To determine if an appropriate instrument is available, one can research literature and available databases to find something suitable to the study.
Read more >
graphql.execution.instrumentation.fieldvalidation - Java
FieldAndArguments. This represents a field and its arguments that may be validated. · FieldValidationEnvironment. This contains all of the field and their ...
Read more >
Validation - REDCap Docs @ QMUL
To improve data quality, use REDCap validation rules. ... One method of doing this is by employing the Validation option in the field...
Read more >
Validate Dynamically Added Input fields - Stack Overflow
When the add button is clicked a new input is dynamically added. However when the form is submitted only the first input field...
Read more >
HTML5 Form Validation With the “pattern” Attribute - Web Design
The validation process evaluates whether the input value is in the correct format before submitting it. For example, if we have an input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found