Skip to content

Exceptions not working as expected with Directive Wiring #79

@jdsalasbarrantes

Description

@jdsalasbarrantes

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions