Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field objects are allowed to be supplied without declaring blocks #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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