-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add error test for defer (#574) * add initial defer transform tests (#576) * initial defer logic (#577) * get transforms actually working for deferred payloads (#578) * improve JsonNodes class * passing in NadelQueryPath instead of List<String> to allow better type safety * remove unused if block * add ability to log errors for defer transforms * add extra defer tests for fields in lists and fields in hydrations * move processing of graphql errors * remove incorrect test * remove unused test * add logic to move transform functions next to each other * add level of abstraction for reused code in transform functions * add assertShouldNeverHappen when prefix does not match query path in JsonNodes * add deep deferred rename transform test * remove empty file * clean up defer transform code * add tests for other transforms * add defer to deep rename transform test
- Loading branch information
Showing
6 changed files
with
596 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
.../test/kotlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredDeepRenameTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package graphql.nadel.tests.next.fixtures.defer.transforms | ||
|
||
import graphql.nadel.NadelExecutionHints | ||
import graphql.nadel.tests.next.NadelIntegrationTest | ||
|
||
open class DeferredDeepRenameTest : NadelIntegrationTest( | ||
query = """ | ||
query { | ||
...@defer { | ||
details { | ||
name # Deep renamed from Issue.name | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
services = listOf( | ||
Service( | ||
name = "defer", | ||
overallSchema = """ | ||
directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
type Query { | ||
details: IssueDetail | ||
} | ||
type IssueDetail { | ||
name: String @renamed(from: "issue.name") | ||
} | ||
|
||
""".trimIndent(), | ||
underlyingSchema = """ | ||
directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
type Issue { | ||
name: String | ||
} | ||
|
||
type IssueDetail { | ||
issue: Issue | ||
} | ||
|
||
type Query { | ||
details: IssueDetail | ||
} | ||
|
||
""".trimIndent(), | ||
runtimeWiring = { wiring -> | ||
wiring | ||
.type("Query") { type -> | ||
type | ||
.dataFetcher("details") { env -> | ||
Any() | ||
} | ||
} | ||
.type("IssueDetail") { type -> | ||
type | ||
.dataFetcher("issue") { env -> | ||
Any() | ||
} | ||
} | ||
.type("Issue") { type -> | ||
type | ||
.dataFetcher("name") { env -> | ||
"Issue-1" | ||
} | ||
} | ||
}, | ||
), | ||
), | ||
) { | ||
override fun makeExecutionHints(): NadelExecutionHints.Builder { | ||
return super.makeExecutionHints() | ||
.deferSupport { true } | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...tlin/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredDeepRenameTestSnapshot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// @formatter:off | ||
package graphql.nadel.tests.next.fixtures.defer.transforms | ||
|
||
import graphql.nadel.tests.next.ExpectedNadelResult | ||
import graphql.nadel.tests.next.ExpectedServiceCall | ||
import graphql.nadel.tests.next.TestSnapshot | ||
import graphql.nadel.tests.next.listOfJsonStrings | ||
import kotlin.Suppress | ||
import kotlin.collections.List | ||
import kotlin.collections.listOf | ||
|
||
private suspend fun main() { | ||
graphql.nadel.tests.next.update<DeferredDeepRenameTest>() | ||
} | ||
|
||
/** | ||
* This class is generated. Do NOT modify. | ||
* | ||
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots | ||
*/ | ||
@Suppress("unused") | ||
public class DeferredDeepRenameTestSnapshot : TestSnapshot() { | ||
override val calls: List<ExpectedServiceCall> = listOf( | ||
ExpectedServiceCall( | ||
service = "defer", | ||
query = """ | ||
| { | ||
| ... @defer { | ||
| details { | ||
| deep_rename__name__issue: issue { | ||
| name | ||
| } | ||
| __typename__deep_rename__name: __typename | ||
| } | ||
| } | ||
| } | ||
""".trimMargin(), | ||
variables = "{}", | ||
result = """ | ||
| { | ||
| "data": {}, | ||
| "hasNext": true | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
""" | ||
| { | ||
| "hasNext": false, | ||
| "incremental": [ | ||
| { | ||
| "path": [], | ||
| "data": { | ||
| "details": { | ||
| "name": "Issue-1" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
""".trimMargin(), | ||
), | ||
), | ||
) | ||
|
||
/** | ||
* ```json | ||
* { | ||
* "data": { | ||
* "details": { | ||
* "name": "Issue-1" | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
override val result: ExpectedNadelResult = ExpectedNadelResult( | ||
result = """ | ||
| { | ||
| "data": { | ||
| "details": null | ||
| }, | ||
| "hasNext": true | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
""" | ||
| { | ||
| "hasNext": false, | ||
| "incremental": [ | ||
| { | ||
| "path": [], | ||
| "data": { | ||
| "details": { | ||
| "name": "Issue-1" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
""".trimMargin(), | ||
), | ||
) | ||
} |
69 changes: 69 additions & 0 deletions
69
...in/graphql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsSkippedIfTrueTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package graphql.nadel.tests.next.fixtures.defer.transforms | ||
|
||
import graphql.nadel.NadelExecutionHints | ||
import graphql.nadel.tests.next.NadelIntegrationTest | ||
|
||
open class DeferredFieldIsSkippedIfTrueTest : NadelIntegrationTest( | ||
query = """ | ||
query { | ||
defer { | ||
...@defer { | ||
hello @skip(if: false) | ||
overallString @skip (if: true) | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
services = listOf( | ||
Service( | ||
name = "defer", | ||
overallSchema = """ | ||
directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
type Query { | ||
defer: DeferApi | ||
} | ||
type DeferApi { | ||
hello: String | ||
overallString: String @renamed(from: "underlyingString") | ||
} | ||
|
||
""".trimIndent(), | ||
underlyingSchema = """ | ||
directive @defer(if: Boolean, label: String) on FRAGMENT_SPREAD | INLINE_FRAGMENT | ||
|
||
type Query { | ||
defer: DeferApi | ||
} | ||
type DeferApi { | ||
hello: String | ||
underlyingString: String | ||
} | ||
|
||
""".trimIndent(), | ||
runtimeWiring = { wiring -> | ||
wiring | ||
.type("Query") { type -> | ||
type | ||
.dataFetcher("defer") { env -> | ||
Any() | ||
} | ||
} | ||
.type("DeferApi") { type -> | ||
type | ||
.dataFetcher("hello") { env -> | ||
"hello there" | ||
} | ||
.dataFetcher("underlyingString") { env -> | ||
"string for the deferred renamed field" | ||
} | ||
} | ||
}, | ||
), | ||
), | ||
) { | ||
override fun makeExecutionHints(): NadelExecutionHints.Builder { | ||
return super.makeExecutionHints() | ||
.deferSupport { true } | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...ql/nadel/tests/next/fixtures/defer/transforms/DeferredFieldIsSkippedIfTrueTestSnapshot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// @formatter:off | ||
package graphql.nadel.tests.next.fixtures.defer.transforms | ||
|
||
import graphql.nadel.tests.next.ExpectedNadelResult | ||
import graphql.nadel.tests.next.ExpectedServiceCall | ||
import graphql.nadel.tests.next.TestSnapshot | ||
import graphql.nadel.tests.next.listOfJsonStrings | ||
import kotlin.Suppress | ||
import kotlin.collections.List | ||
import kotlin.collections.listOf | ||
|
||
private suspend fun main() { | ||
graphql.nadel.tests.next.update<DeferredFieldIsSkippedIfTrueTest>() | ||
} | ||
|
||
/** | ||
* This class is generated. Do NOT modify. | ||
* | ||
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots | ||
*/ | ||
@Suppress("unused") | ||
public class DeferredFieldIsSkippedIfTrueTestSnapshot : TestSnapshot() { | ||
override val calls: List<ExpectedServiceCall> = listOf( | ||
ExpectedServiceCall( | ||
service = "defer", | ||
query = """ | ||
| { | ||
| defer { | ||
| ... @defer { | ||
| hello | ||
| } | ||
| } | ||
| } | ||
""".trimMargin(), | ||
variables = "{}", | ||
result = """ | ||
| { | ||
| "data": { | ||
| "defer": {} | ||
| }, | ||
| "hasNext": true | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
""" | ||
| { | ||
| "hasNext": false, | ||
| "incremental": [ | ||
| { | ||
| "path": [ | ||
| "defer" | ||
| ], | ||
| "data": { | ||
| "hello": "hello there" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
""".trimMargin(), | ||
), | ||
), | ||
) | ||
|
||
/** | ||
* ```json | ||
* { | ||
* "data": { | ||
* "defer": { | ||
* "hello": "hello there" | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
override val result: ExpectedNadelResult = ExpectedNadelResult( | ||
result = """ | ||
| { | ||
| "data": { | ||
| "defer": {} | ||
| }, | ||
| "hasNext": true | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
""" | ||
| { | ||
| "hasNext": false, | ||
| "incremental": [ | ||
| { | ||
| "path": [ | ||
| "defer" | ||
| ], | ||
| "data": { | ||
| "hello": "hello there" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
""".trimMargin(), | ||
), | ||
) | ||
} |
Oops, something went wrong.