Skip to content

Nested input validation #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pelletier197 opened this issue Sep 28, 2020 · 1 comment
Closed

Nested input validation #28

pelletier197 opened this issue Sep 28, 2020 · 1 comment

Comments

@pelletier197
Copy link
Contributor

pelletier197 commented Sep 28, 2020

Hello!

First of all thank you for providing this plugin. It saved us a lot of time when using spring-boot, and it's really great to have the directives in the graphQL model since it's really easy to document the queries this way.

To setup this plugin with spring-boot, we used the latest spring-graphql-kickstart, version 7.1.0 and this library version 15.0.1. To create and autowire the SchemaDirectiveWiring, I used the following

    @Bean
    fun createDirectiveWiringList(): List<SchemaDirectiveWiring> {
        return listOf(
            createRequestValidationWiring()
        )
    }

    private fun createRequestValidationWiring(): SchemaDirectiveWiring {
        val validationRules = ValidationRules.newValidationRules()
            .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
            .build()
        return ValidationSchemaWiring(validationRules)
    }

which seems to be working fine in some cases.

I have a query that looks in my application

{
   search(query: "test") {
      results(paging: { first: 10, skip: 0 })
   }
}

and I want to validate the paging parameter with the following.

input Paging {
    first: Int = 10 @Positive,
    skip: Int = 0 @PositiveOrZero
}

In the case I pointed out, I have no issue with the plugin, and the validation works as expected.

However, I have another endpoint that looks like this

{
   searchWithSorting(query: "test") {
      results(pagingAndSorting: { paging: { first: 10, skip: 0 }, sorting: [...] })
   }
}

and in this case, the validation fails to execute.

I debugged a little, and I found out that the class of this repository graphql.validation.rules.ValidationRules does not look for rules in nested arguments, which seems to cause this problem, so the validation seems to be completely skipped. Therefore, since PagingAndSorting does not have any validations, the input object is not validated.

Thank you for your help!

@pelletier197
Copy link
Contributor Author

After some more checking, this is exactly the same issue as for #17 , so i'll be closing this one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant