Skip to content

Commit

Permalink
Merge pull request #1 from rudy-on-rails/rudy-on-rails/allow-field-ob…
Browse files Browse the repository at this point in the history
…ject-declarations-to-not-use-blocks

Field objects are allowed to be supplied without declaring blocks
  • Loading branch information
rudy-on-rails authored Jan 20, 2021
2 parents b4f3761 + fa91f3b commit 5eea46c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/kotlin/me/lazmaid/kraph/Kraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Kraph(f: Kraph.() -> Unit) {
open inner class FieldBuilder {
internal val fields = arrayListOf<Field>()

fun fieldObject(name: String, alias: String? = null, args: Map<String, Any>? = null, builder: FieldBlock) {
fun fieldObject(name: String, alias: String? = null, args: Map<String, Any>? = null, builder: FieldBlock? = null) {
addField(name, alias, args, builder)
}

Expand Down
15 changes: 15 additions & 0 deletions core/src/test/kotlin/me/lazmaid/kraph/test/BuilderSpek.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ class BuilderSpek : Spek({
}, throws(noFieldInSelectionSetMessageMatcher("test")))
}
}
given("sample query with object and no supplied field builder") {
val query = Kraph {
query {
fieldObject("test")
}
}
it("should not throw a NoFieldsInSelectionSetException and build the request correctly") {
assertThat(
query.toRequestString(),
equalTo(
"{\"query\": \"query { test }\", \"variables\": null, \"operationName\": null}"
)
)
}
}
given("sample mutation") {
val query = Kraph {
mutation {
Expand Down

0 comments on commit 5eea46c

Please sign in to comment.