-
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.
- Loading branch information
Showing
2 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
test/src/test/kotlin/graphql/nadel/tests/next/fixtures/hydration/HydrationAtQueryTypeTest.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,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" | ||
} | ||
} | ||
}, | ||
), | ||
), | ||
) |
92 changes: 92 additions & 0 deletions
92
...st/kotlin/graphql/nadel/tests/next/fixtures/hydration/HydrationAtQueryTypeTestSnapshot.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,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( | ||
), | ||
) | ||
} |