Skip to content

Commit

Permalink
Add plain hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf committed Sep 9, 2024
1 parent 4b36bb8 commit 7de5eb6
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package graphql.nadel.tests.next.fixtures.hydration

import graphql.nadel.engine.util.strictAssociateBy
import graphql.nadel.tests.next.NadelIntegrationTest

class HydrationAtQueryTypeTest : NadelIntegrationTest(
query = """
query {
myIssue {
title
}
}
""".trimIndent(),
services = listOf(
Service(
name = "issues",
overallSchema = """
type Query {
issueById(id: ID!): Issue
myIssueKey: ID! @hidden
myIssue: Issue
@hydrated(
service: "issues"
field: "issueById"
arguments: [{name: "id", value: "$source.myIssueKey"}]
)
}
type Issue {
id: ID!
title: String
}
""".trimIndent(),
runtimeWiring = { wiring ->
data class Issue(
val id: String,
val title: String,
)

val issuesByIds = listOf(
Issue(id = "hello", title = "Hello there"),
Issue(id = "afternoon", title = "Good afternoon"),
Issue(id = "bye", title = "Farewell"),
).strictAssociateBy { it.id }

wiring
.type("Query") { type ->
type
.dataFetcher("issueById") { env ->
issuesByIds[env.getArgument<String>("id")]
}
.dataFetcher("myIssueKey") { env ->
"bye"
}
}
},
),
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// @formatter:off
package graphql.nadel.tests.next.fixtures.hydration

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<HydrationAtQueryTypeTest>()
}

/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
*/
@Suppress("unused")
public class HydrationAtQueryTypeTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "issues",
query = """
| {
| hydration__myIssue__myIssueKey: myIssueKey
| __typename__hydration__myIssue: __typename
| }
""".trimMargin(),
variables = "{}",
result = """
| {
| "data": {
| "hydration__myIssue__myIssueKey": "bye",
| "__typename__hydration__myIssue": "Query"
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
),
ExpectedServiceCall(
service = "issues",
query = """
| {
| issueById(id: "bye") {
| title
| }
| }
""".trimMargin(),
variables = "{}",
result = """
| {
| "data": {
| "issueById": {
| "title": "Farewell"
| }
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
),
)

/**
* ```json
* {
* "data": {
* "myIssue": {
* "title": "Farewell"
* }
* }
* }
* ```
*/
override val result: ExpectedNadelResult = ExpectedNadelResult(
result = """
| {
| "data": {
| "myIssue": {
| "title": "Farewell"
| }
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
)
}

0 comments on commit 7de5eb6

Please sign in to comment.