Skip to content

Commit

Permalink
tests for defer queries with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarker2 committed Jun 18, 2024
1 parent 1f2b9a5 commit da844c7
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ public class ComprehensiveDeferQueryWithDifferentServiceCallsSnapshot : TestSnap
| "path": [
| "user"
| ],
| "label": "team-details",
| "data": {
| "teamName": "The Unicorns",
| "teamMembers": [
| "Felipe",
| "Franklin"
| ]
| "profilePicture": "https://examplesite.com/user/profile_picture.jpg"
| }
| }
| ]
Expand All @@ -116,8 +111,13 @@ public class ComprehensiveDeferQueryWithDifferentServiceCallsSnapshot : TestSnap
| "path": [
| "user"
| ],
| "label": "team-details",
| "data": {
| "profilePicture": "https://examplesite.com/user/profile_picture.jpg"
| "teamName": "The Unicorns",
| "teamMembers": [
| "Felipe",
| "Franklin"
| ]
| }
| }
| ]
Expand All @@ -133,12 +133,12 @@ public class ComprehensiveDeferQueryWithDifferentServiceCallsSnapshot : TestSnap
* "data": {
* "user": {
* "name": "Steven",
* "profilePicture": "https://examplesite.com/user/profile_picture.jpg",
* "teamName": "The Unicorns",
* "teamMembers": [
* "Felipe",
* "Franklin"
* ]
* ],
* "profilePicture": "https://examplesite.com/user/profile_picture.jpg"
* },
* "product": {
* "productName": "Awesome Product",
Expand Down Expand Up @@ -188,13 +188,8 @@ public class ComprehensiveDeferQueryWithDifferentServiceCallsSnapshot : TestSnap
| "path": [
| "user"
| ],
| "label": "team-details",
| "data": {
| "teamName": "The Unicorns",
| "teamMembers": [
| "Felipe",
| "Franklin"
| ]
| "profilePicture": "https://examplesite.com/user/profile_picture.jpg"
| }
| }
| ]
Expand All @@ -208,8 +203,13 @@ public class ComprehensiveDeferQueryWithDifferentServiceCallsSnapshot : TestSnap
| "path": [
| "user"
| ],
| "label": "team-details",
| "data": {
| "profilePicture": "https://examplesite.com/user/profile_picture.jpg"
| "teamName": "The Unicorns",
| "teamMembers": [
| "Felipe",
| "Franklin"
| ]
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// @formatter:off
package graphql.nadel.tests.next.fixtures.defer

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

/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
*/
@Suppress("unused")
public class DeferOnListItemsTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "defer",
query = """
| {
| defer {
| list {
| fast
| ... @defer {
| slow
| }
| }
| }
| }
""".trimMargin(),
variables = "{}",
result = """
| {
| "data": {
| "defer": {
| "list": [
| {
| "fast": "fastString"
| },
| {
| "fast": "fastString"
| }
| ]
| }
| },
| "hasNext": true
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
"""
| {
| "hasNext": false,
| "incremental": [
| {
| "path": [
| "defer",
| "list",
| 1
| ],
| "data": {
| "slow": "slowString"
| }
| }
| ]
| }
""".trimMargin(),
"""
| {
| "hasNext": true,
| "incremental": [
| {
| "path": [
| "defer",
| "list",
| 0
| ],
| "data": {
| "slow": "slowString"
| }
| }
| ]
| }
""".trimMargin(),
),
),
)

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

import graphql.GraphqlErrorBuilder
import graphql.execution.DataFetcherResult
import graphql.nadel.NadelExecutionHints
import graphql.nadel.tests.next.NadelIntegrationTest

open class DeferWithErrorTest : 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
}

""".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 ->
DataFetcherResult.newResult<String>()
.error(
GraphqlErrorBuilder.newError()
.message("An error occurred while fetching 'slow'")
.build()
)
.build()
}
}
},
),
),
) {
override fun makeExecutionHints(): NadelExecutionHints.Builder {
return super.makeExecutionHints()
.deferSupport { true }
}
}
Loading

0 comments on commit da844c7

Please sign in to comment.