Skip to content

Commit

Permalink
Add tests for @defer with other transforms (#586)
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
sbarker2 committed Sep 2, 2024
1 parent 5630e9a commit c17dd52
Show file tree
Hide file tree
Showing 6 changed files with 596 additions and 0 deletions.
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 }
}
}
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(),
),
)
}
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 }
}
}
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(),
),
)
}
Loading

0 comments on commit c17dd52

Please sign in to comment.