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

Add tests for remaining transforms with defer #590

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6f25a60
add error test for defer (#574)
sbarker2 Aug 19, 2024
aa1248a
add initial defer transform tests (#576)
sbarker2 Aug 19, 2024
96654b7
initial defer logic (#577)
sbarker2 Aug 19, 2024
5a8e505
get transforms actually working for deferred payloads (#578)
sbarker2 Aug 19, 2024
7ea4f4c
improve JsonNodes class
sbarker2 Aug 20, 2024
d64d395
passing in NadelQueryPath instead of List<String> to allow better typ…
sbarker2 Aug 25, 2024
8d98b98
remove unused if block
sbarker2 Aug 25, 2024
876b302
add ability to log errors for defer transforms
sbarker2 Aug 26, 2024
76cfa21
add extra defer tests for fields in lists and fields in hydrations
sbarker2 Aug 26, 2024
59de250
move processing of graphql errors
sbarker2 Aug 27, 2024
8d1d18b
remove incorrect test
sbarker2 Aug 27, 2024
83ceb7f
remove unused test
sbarker2 Aug 27, 2024
fe5827d
add logic to move transform functions next to each other
sbarker2 Aug 27, 2024
ceb3c56
add level of abstraction for reused code in transform functions
sbarker2 Aug 28, 2024
35d74db
add assertShouldNeverHappen when prefix does not match query path in …
sbarker2 Aug 28, 2024
75285f7
add deep deferred rename transform test
sbarker2 Aug 28, 2024
b3196a1
remove empty file
sbarker2 Aug 28, 2024
96cd51d
clean up defer transform code
sbarker2 Aug 28, 2024
fc34be3
Merge branch 'apply-transforms-to-defer-payloads' into add-other-tran…
sbarker2 Aug 28, 2024
92863a1
add tests for other transforms
sbarker2 Aug 28, 2024
691665f
add defer to deep rename transform test
sbarker2 Aug 30, 2024
d0b7eb3
Merge branch 'master' into add-other-transforms
sbarker2 Sep 1, 2024
1037769
add tests for other transforms
sbarker2 Sep 13, 2024
b1165ac
Merge branch 'master' into add-other-transforms
sbarker2 Sep 13, 2024
1f57de1
remove unused test snapshot
sbarker2 Sep 13, 2024
7a52d51
fix NadelServiceTypeFilterTransform test
sbarker2 Sep 15, 2024
2d0625e
update test package
sbarker2 Sep 15, 2024
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
@@ -0,0 +1,62 @@
package graphql.nadel.tests.next.fixtures.defer.transforms

import graphql.nadel.NadelExecutionHints
import graphql.nadel.tests.next.NadelIntegrationTest

open class DeferWithTransformThrowsErrorTest : NadelIntegrationTest(
query = """
query {
defer {
hello
... @defer(label: "slow-defer") {
slow
}
}
}
""".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
slow: String @renamed(from: "underlyingSlow")
}

""".trimIndent(),
runtimeWiring = { wiring ->
data class DeferApi(
val hello: String,
val slow: String,
)

wiring
.type("Query") { type ->
type
.dataFetcher("defer") { env ->
Any()
}
}
.type("DeferApi") { type ->
type
.dataFetcher("hello") { env ->
"helloString"
}
.dataFetcher("slow") { env ->
throw RuntimeException("An error occurred while fetching 'slow'")
}
}
},
),
),
) {
override fun makeExecutionHints(): NadelExecutionHints.Builder {
return super.makeExecutionHints()
.deferSupport { true }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// @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<DeferWithTransformThrowsErrorTest>()
}

/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
*/
@Suppress("unused")
public class DeferWithTransformThrowsErrorTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "defer",
query = """
| {
| defer {
| hello
| ... @defer(label: "slow-defer") {
| rename__slow__underlyingSlow: underlyingSlow
| __typename__rename__slow: __typename
| }
| }
| }
""".trimMargin(),
variables = " {}",
result = """
| {
| "data": {
| "defer": {
| "hello": "helloString"
| }
| },
| "hasNext": true
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
"""
| {
| "hasNext": false,
| "incremental": [
| {
| "path": [
| "defer"
| ],
| "label": "slow-defer",
| "data": {
| "rename__slow__underlyingSlow": null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the error in the result?

| "__typename__rename__slow": "DeferApi"
| }
| }
| ]
| }
""".trimMargin(),
),
),
)

/**
* ```json
* {
* "data": {
* "defer": {
* "hello": "helloString",
* "slow": null
* }
* }
* }
* ```
*/
override val result: ExpectedNadelResult = ExpectedNadelResult(
result = """
| {
| "data": {
| "defer": {
| "hello": "helloString"
| }
| },
| "hasNext": true
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
"""
| {
| "hasNext": false,
| "incremental": [
| {
| "path": [
| "defer"
| ],
| "label": "slow-defer",
| "data": {
| "slow": null
| }
| }
| ]
| }
""".trimMargin(),
),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package graphql.nadel.tests.next.fixtures.defer.transforms

import graphql.nadel.NadelExecutionHints
import graphql.nadel.tests.next.NadelIntegrationTest

/**
* The `ConfluenceLegacyPathType` input type was renamed.
*
* In the test snapshot we ensure the variable is defined as `PathType`.
*
* This tests the NadelRenameArgumentInputTypesTransform with defer
*/
class DeferredRenamedInputTypeTest : NadelIntegrationTest(
query = """
query {
me {
profilePicture {
...@defer {
path(type: ABSOLUTE)
}
}
}
}
""".trimIndent(),
services = listOf(
Service(
name = "confluence_legacy",
overallSchema = """
type Query {
me: ConfluenceLegacyUser
}
type ConfluenceLegacyUser @renamed(from: "User") {
profilePicture: ConfluenceLegacyProfilePicture
}
type ConfluenceLegacyProfilePicture @renamed(from: "ProfilePicture") {
path(type: ConfluenceLegacyPathType!): String
}
enum ConfluenceLegacyPathType @renamed(from: "PathType") {
ABSOLUTE
RELATIVE
}
""".trimIndent(),
runtimeWiring = { wiring ->
data class ProfilePicture(
val absolutePath: String,
val relativePath: String,
)

data class User(
val profilePicture: ProfilePicture,
)

wiring
.type("Query") { type ->
type
.dataFetcher("me") { env ->
User(
profilePicture = ProfilePicture(
relativePath = "/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70",
absolutePath = "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70",
),
)
}
}
.type("ProfilePicture") { type ->
type
.dataFetcher("path") { env ->
val pfp = env.getSource<ProfilePicture>()!!
when (val urlType = env.getArgument<String>("type")) {
"ABSOLUTE" -> pfp.absolutePath
"RELATIVE" -> pfp.relativePath
else -> throw IllegalArgumentException(urlType)
}
}
}
},
),
),
) {
override fun makeExecutionHints(): NadelExecutionHints.Builder {
return super.makeExecutionHints()
// todo: this should be on by default
.allDocumentVariablesHint {
true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// @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<DeferredRenamedInputTypeTest>()
}

/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
*/
@Suppress("unused")
public class DeferredRenamedInputTypeTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "confluence_legacy",
query = """
| query (${'$'}v0: PathType!) {
| me {
| profilePicture {
| path(type: ${'$'}v0)
| }
| }
| }
""".trimMargin(),
variables = """
| {
| "v0": "ABSOLUTE"
| }
""".trimMargin(),
result = """
| {
| "data": {
| "me": {
| "profilePicture": {
| "path": "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70"
| }
| }
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
),
)

/**
* ```json
* {
* "data": {
* "me": {
* "profilePicture": {
* "path": "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70"
* }
* }
* }
* }
* ```
*/
override val result: ExpectedNadelResult = ExpectedNadelResult(
result = """
| {
| "data": {
| "me": {
| "profilePicture": {
| "path": "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no incremental data in the result

| }
| }
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
)
}
Loading
Loading