Fragments
eduardostuart opened this issue · comments
Is possible to build "fragments" with Kraph?
Example:
Fragment:
fragment something on SomethingXX {
id
name
}
Full query:
query queryname($input: QueryInput!) {
queryname(input: $input) {
message
... on SomeResult {
somethinghere {
...something
}
}
}
}
Well, you can do something like this.
Kraph {
val userFragment: Kraph.FieldBuilder.() -> Unit = {
field("name")
field("avatar")
}
query {
fieldObject("youtuber", builder = userFragment)
fieldObject("subscriber", builder = userFragment)
}
}
Since Fragment is a set of fields, It would be best to declare as a variable and use in the query
or fieldObject()
.
Thank you, @VerachadW .
And how can I build those inline fragments, with "... on"
?
This one will be a bit ugly. You can use the `fieldObject()` and put "...on something" to produce the desired result. I will improve this one later since I'm quite busy right now. If you have an idea feel free to open PR for that 😉.
It works! Thanks a lot @VerachadW .