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

Fixed issue top level fields with directives are being ignored #66

Merged
merged 1 commit into from
Nov 28, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ class ParallelRequestExecutor(val schema: DefaultSchema) : RequestExecutor, Coro
val data = root.putObject("data")

val resultMap = plan.toMapAsync {
writeOperation(
val ctx = ExecutionContext(Variables(schema, variables, it.variables), context)
if (determineInclude(ctx, it)) writeOperation(
isSubscription = plan.isSubscription,
ctx = ExecutionContext(Variables(schema, variables, it.variables), context),
ctx = ctx,
node = it,
operation = it.field as Field.Function<*, *>
)
) else null
}

for (operation in plan) {
data.set(operation.aliasOrKey, resultMap[operation])
if (resultMap[operation] != null) { // Remove all by skip/include directives
data.set(operation.aliasOrKey, resultMap[operation])
}
}

return objectWriter.writeValueAsString(root)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.apurebase.kgraphql.specification.typesystem

import com.apurebase.kgraphql.Specification
import com.apurebase.kgraphql.extractOrNull
import com.apurebase.kgraphql.*
import com.apurebase.kgraphql.integration.BaseSchemaTest
import org.amshove.kluent.shouldEqual
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.CoreMatchers.nullValue
import org.hamcrest.MatcherAssert.assertThat
Expand Down Expand Up @@ -38,6 +38,21 @@ class DirectivesSpecificationTest : BaseSchemaTest() {
assertThat(extractOrNull(mapNeither, "data/film/year"), notNullValue())
}

@Test
fun `query with @include and @skip directive on field object`() {
val mapWithSkip = execute("{ number(big: true), film @skip(if: true) { title } }")
mapWithSkip.extract<String?>("data/film") shouldEqual null

val mapWithoutSkip = execute("{ number(big: true), film @skip(if: false) { title } }")
mapWithoutSkip.extract<String>("data/film/title") shouldEqual "Prestige"

val mapWithInclude = execute("{ number(big: true), film @include(if: true) { title } }")
mapWithInclude.extract<String?>("data/film/title") shouldEqual "Prestige"

val mapWithoutInclude = execute("{ number(big: true), film @include(if: false) { title } }")
mapWithoutInclude.extract<String>("data/film") shouldEqual null
}

@Test
fun `query with @include directive on field with variable`(){
val map = execute(
Expand Down