spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.53k stars 306 forks source link

GraphQlTester - ToEntity also converting data for sub-entities #1064

Closed Hugofbf21 closed 23 hours ago

Hugofbf21 commented 1 month ago

Hello! I have been writing some integration tests for my example class:

class ThingResponse(
        val Id: String,,
        val name: String,
        val isCool: Boolean,
        val associatedEntity: AssociatedEntity?
    )

class AssociatedEntity(
        Id: UUID,
        val name: String,
        val wow: String
    )

In the test:

val responseFlux = documentName("onSubscription")
                .variable("something", "123")
                .variable("Something else", "3b23e223-2edb-4f5e-8e96-2e2607abd22b")
                .executeSubscription()
                .toFlux()

            val verifier = StepVerifier.create(responseFlux)
                .assertNext { response ->
                    run {
                        // should bring 5 thingResponses
                        var entities = response.path("onSubscription").entityList(ThingResponse::class.java)
                            .hasSize(5).get()
                        // 2 thingResponses should come with associatedEntity
                        //TODO how could i get the associatedEntity? without acessing [i] 
                        // where i would know the index
                    }
                }
                .thenCancel()
                .verifyLater()

The variable entities the fields come all mapped correctly besides the associatedEntity that comes always at null, is there any way the conversion of data could "cascade" down to the sub entities? If this is already implemented in another way it would be awesome to know as well.

Further clarification:

How could I verify if it has a value and then get it.

rstoyanchev commented 1 month ago

Can you provide a small sample please?

spring-projects-issues commented 4 weeks ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 3 weeks ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.