1

Right now, my project uses netflix/springboot/kotlin.

I want to have an SDL like:

type Shows {
  name: String!
  writer: Writer!
}

type Writer {
  name: String!
}

In this case, a show must have a writer.

When I codegen, I get the relevant Kotlin types.

Now, if I want to implement:

...
@DgsData(parent = 'Query', field = 'show')
fun show(@InputArgument id: String): GeneratedShow {
  val show = ShowService.getShow(id);
  // I can't return `show` here because `show` only has `name` and `writerId`.
}

My ShowService.getShow type only returns a name and a writerId and I don't want to force my function to have to "hydrate" (extra network call) the writer on every graphql call. This would be a waste of resources even if my client does not specify the writer subfield.

But I cannot get this to compile because this function requires a writer field on it. I also don't want to make writer a nullable field in my schema, because it is required.

How do you solve this issue?

Willy Xiao
  • 370
  • 1
  • 12
  • I know that one option is to do something like this: https://stackoverflow.com/a/71613565/3843383, where I can provide an "empty" list if the request did not include the subfield I'm interested in, but that feels like a bit too manual and not typesafe. – Willy Xiao Sep 03 '22 at 19:42

0 Answers0