-
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.
Add support for defer payload label (#565)
- Loading branch information
Showing
3 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
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
97 changes: 97 additions & 0 deletions
97
.../test/kotlin/graphql/nadel/tests/next/fixtures/hydration/defer/HydrationDeferLabelTest.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,97 @@ | ||
package graphql.nadel.tests.next.fixtures.hydration.defer | ||
|
||
import graphql.nadel.NadelExecutionHints | ||
import graphql.nadel.engine.util.strictAssociateBy | ||
import graphql.nadel.tests.next.NadelIntegrationTest | ||
|
||
open class HydrationDeferLabelTest : NadelIntegrationTest( | ||
query = """ | ||
query { | ||
issue(id: "ari:cloud:jira::issue/1") { | ||
id | ||
... @defer(label: "who is assigned this issue") { | ||
assignee { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
services = listOf( | ||
Service( | ||
name = "issues", | ||
overallSchema = """ | ||
type Query { | ||
issue(id: ID!): Issue | ||
} | ||
type Issue { | ||
id: ID! | ||
assigneeId: ID! @hidden | ||
assignee: User | ||
@hydrated( | ||
service: "users" | ||
field: "user" | ||
arguments: [{name: "id", value: "$source.assigneeId"}] | ||
) | ||
} | ||
""".trimIndent(), | ||
runtimeWiring = { wiring -> | ||
data class Issue( | ||
val id: String, | ||
val assigneeId: String, | ||
) | ||
|
||
val issuesById: Map<String, Issue> = listOf( | ||
Issue( | ||
id = "ari:cloud:jira::issue/1", | ||
assigneeId = "ari:cloud:jira::user/1", | ||
), | ||
).strictAssociateBy { it.id } | ||
|
||
wiring | ||
.type("Query") { type -> | ||
type.dataFetcher("issue") { env -> | ||
issuesById[env.getArgument("id")] | ||
} | ||
} | ||
}, | ||
), | ||
Service( | ||
name = "users", | ||
overallSchema = """ | ||
type Query { | ||
user(id: ID!): User | ||
} | ||
type User { | ||
id: ID! | ||
name: String! | ||
} | ||
""".trimIndent(), | ||
runtimeWiring = { wiring -> | ||
data class User( | ||
val id: String, | ||
val name: String, | ||
) | ||
|
||
val usersById = listOf( | ||
User( | ||
id = "ari:cloud:jira::user/1", | ||
name = "Franklin", | ||
), | ||
).strictAssociateBy { it.id } | ||
|
||
wiring | ||
.type("Query") { type -> | ||
type.dataFetcher("user") { env -> | ||
usersById[env.getArgument("id")] | ||
} | ||
} | ||
}, | ||
), | ||
), | ||
) { | ||
override fun makeExecutionHints(): NadelExecutionHints.Builder { | ||
return super.makeExecutionHints() | ||
.deferSupport { true } | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...tlin/graphql/nadel/tests/next/fixtures/hydration/defer/HydrationDeferLabelTestSnapshot.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,120 @@ | ||
// @formatter:off | ||
package graphql.nadel.tests.next.fixtures.hydration.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 | ||
|
||
private suspend fun main() { | ||
graphql.nadel.tests.next.update<HydrationDeferLabelTest>() | ||
} | ||
|
||
/** | ||
* This class is generated. Do NOT modify. | ||
* | ||
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots | ||
*/ | ||
@Suppress("unused") | ||
public class HydrationDeferLabelTestSnapshot : TestSnapshot() { | ||
override val calls: List<ExpectedServiceCall> = listOf( | ||
ExpectedServiceCall( | ||
service = "issues", | ||
query = """ | ||
| { | ||
| issue(id: "ari:cloud:jira::issue/1") { | ||
| id | ||
| hydration__assignee__assigneeId: assigneeId | ||
| __typename__hydration__assignee: __typename | ||
| } | ||
| } | ||
""".trimMargin(), | ||
variables = "{}", | ||
result = """ | ||
| { | ||
| "data": { | ||
| "issue": { | ||
| "id": "ari:cloud:jira::issue/1", | ||
| "hydration__assignee__assigneeId": "ari:cloud:jira::user/1", | ||
| "__typename__hydration__assignee": "Issue" | ||
| } | ||
| } | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
), | ||
), | ||
ExpectedServiceCall( | ||
service = "users", | ||
query = """ | ||
| { | ||
| user(id: "ari:cloud:jira::user/1") { | ||
| name | ||
| } | ||
| } | ||
""".trimMargin(), | ||
variables = "{}", | ||
result = """ | ||
| { | ||
| "data": { | ||
| "user": { | ||
| "name": "Franklin" | ||
| } | ||
| } | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
), | ||
), | ||
) | ||
|
||
/** | ||
* ```json | ||
* { | ||
* "data": { | ||
* "issue": { | ||
* "id": "ari:cloud:jira::issue/1", | ||
* "assignee": { | ||
* "name": "Franklin" | ||
* } | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
override val result: ExpectedNadelResult = ExpectedNadelResult( | ||
result = """ | ||
| { | ||
| "data": { | ||
| "issue": { | ||
| "id": "ari:cloud:jira::issue/1" | ||
| } | ||
| }, | ||
| "hasNext": true | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
""" | ||
| { | ||
| "hasNext": false, | ||
| "incremental": [ | ||
| { | ||
| "path": [ | ||
| "issue" | ||
| ], | ||
| "label": "who is assigned this issue", | ||
| "data": { | ||
| "assignee": { | ||
| "name": "Franklin" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
""".trimMargin(), | ||
), | ||
) | ||
} |