You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my first experience building a GraphQL API. My team is using Netflix DGS with Spring Boot on the backend side to implement this API. I found a situation that I am not sure what is the proper way to handle. Please see the code snippets below:
GraphQL schema
type LegalEntity {
id: UUID!
name: String
..other properties (omitted for brevity)
}
type Contract {
id: UUID!
startDate: Date!
endDate: Date
licensor: LegalEntity!
.. other properties (omitted for brevity)
}
Generated Kotlin code
public data class LegalEntity(
@JsonProperty("id")
public val id: String,
@JsonProperty("name")
public val name: String? = null
) {
public companion object
}
public data class Contract(
@JsonProperty("id")
public val id: String,
@JsonProperty("startDate")
public val startDate: LocalDate,
@JsonProperty("endDate")
public val endDate: LocalDate? = null,
@JsonProperty("licensor")
public val licensor: LegalEntity
) {
public companion object
}
My doubt is about how to handle the non-nullable Contract.licensor property when the backend receives a call that doesn't request the licensor, e.g.:
Ideally I don't want to load the licensor only because the property on the generated class is non-nullable (i.e. to make the compiler happy), that would be wasteful since the frontend would discard the licensor anyway.
What am I supposed to do in this situation? Retrieve the licensor anyway and return it, set a fake value and return it, or do something else?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
This is my first experience building a GraphQL API. My team is using Netflix DGS with Spring Boot on the backend side to implement this API. I found a situation that I am not sure what is the proper way to handle. Please see the code snippets below:
GraphQL schema
Generated Kotlin code
My doubt is about how to handle the non-nullable Contract.licensor property when the backend receives a call that doesn't request the licensor, e.g.:
Ideally I don't want to load the licensor only because the property on the generated class is non-nullable (i.e. to make the compiler happy), that would be wasteful since the frontend would discard the licensor anyway.
What am I supposed to do in this situation? Retrieve the licensor anyway and return it, set a fake value and return it, or do something else?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions