Skip to content
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

Exceptions not working as expected with Directive Wiring #79

Open
jdsalasbarrantes opened this issue Sep 27, 2022 · 2 comments
Open

Exceptions not working as expected with Directive Wiring #79

jdsalasbarrantes opened this issue Sep 27, 2022 · 2 comments

Comments

@jdsalasbarrantes
Copy link

Describe the bug

I'm trying to connect kotlin, spring for graphql, and the validation feature, but when I add the directive wiring, the exceptions thrown in the service layer are not being displayed correctly.

Config:

@Configuration
class GraphQLConfig {

    @Bean
    fun runtimeWiringConfigurer(): RuntimeWiringConfigurer {
        val validationRules = ValidationRules.newValidationRules()
            .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
            .build()
        val schemaWiring = ValidationSchemaWiring(validationRules)

        return RuntimeWiringConfigurer { builder: RuntimeWiring.Builder ->
            builder.directiveWiring(schemaWiring).build()
        }
    }
}

Controller:

 @MutationMapping
  fun createCourse(
      @Arguments createCourseDto: CreateCourseDto
  ): CourseDto {
      throw RuntimeException("exception from controller")
  }

Graphql:

directive @NotBlank(message : String! = "graphql.validation.NotBlank.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

createCourse(
     name: String! @NotBlank
 ): Course

type Course {
 id: ID
 name: String
}

When I call this endpoint, the result is an empty object, in the background, an exception is being thrown (check the controller snippet above)

{
  "data": {
    "createCourse": {
      "id": null,
      "name": null
    }
  }
}

But If I remove the directive wiring config:

//@Configuration
//class GraphQLConfig {
//
//    @Bean
//    fun runtimeWiringConfigurer(): RuntimeWiringConfigurer {
//        val validationRules = ValidationRules.newValidationRules()
//            .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
//            .build()
//        val schemaWiring = ValidationSchemaWiring(validationRules)
//
//        return RuntimeWiringConfigurer { builder: RuntimeWiring.Builder ->
//            builder.directiveWiring(schemaWiring).build()
//        }
//    }
//}

I do get the exception as usual:

{
  "errors": [
    {
      "message": "INTERNAL_ERROR for a9883b45-f615-258a-4f7a-bda5b432d485",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "createCourse"
      ],
      "extensions": {
        "classification": "INTERNAL_ERROR"
      }
    }
  ],
  "data": {
    "createCourse": null
  }
}

Is it something wrong with the code, or could this be a bug?

@JBO24
Copy link

JBO24 commented Oct 28, 2022

We are running into the same issue. Do you have any solution for this?

@jdsalasbarrantes
Copy link
Author

Hi @JBO24, I ended up implementing my own version of the ValidationSchemaWiring, using only the onArgument function.
Another alternative I consider was using the spring validator

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

2 participants