Skip to content

Commit

Permalink
Add conditional ATI test using Regex
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf committed Sep 6, 2024
1 parent aeb5995 commit 3a2626f
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ private fun make(overallSchema: Document): String {
}
}
.asSequence()
.filter {
// Ignore synthetic elements
if (it is DirectivesContainer<*>) {
!it.hasDirective("synthetic")
} else {
true
}
}
.map {
// In theory the overall schema can extend types not in this schema… Let's leave that for another day
when (val type = it) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package graphql.nadel.tests.next.fixtures.hydration.conditional

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

// ari:cloud:jira:TEST--67b8ae80-cf1a-4de7-b77c-3f8ff51977b3:issue/10000
class ConditionalHydrationRegexTest : NadelIntegrationTest(
query = """
query {
search {
object {
__typename
}
}
}
""".trimIndent(),
services = listOf(
Service(
name = "search",
overallSchema = """
directive @synthetic on UNION
type Query {
search: [SearchResult]
}
type SearchResult {
objectId: ID!
object: SearchResultObject
@hydrated(
service: "issues"
field: "issueById"
arguments: [{name: "id", value: "$source.objectId"}]
when: {
result: {
sourceField: "objectId"
predicate: {
matches: "^ari:cloud:jira:[^:]+:issue/.+$"
}
}
}
)
@hydrated(
service: "identity"
field: "userById"
arguments: [{name: "id", value: "$source.objectId"}]
when: {
result: {
sourceField: "objectId"
predicate: {
matches: "^ari:cloud:identity::user/.+$"
}
}
}
)
}
union SearchResultObject @synthetic = Issue | User
""".trimIndent(),
runtimeWiring = { wiring ->
data class SearchResult(val objectId: String)

val results = listOf(
SearchResult(
objectId = "ari:cloud:jira:TEST--67b8ae80-cf1a-4de7-b77c-3f8ff51977b3:issue/10000",
),
SearchResult(
objectId = "ari:cloud:identity::user/1",
),
)

wiring
.type("Query"){type->
type
.dataFetcher("search"){
results
}
}
},
),
Service(
name = "issues",
overallSchema = """
type Query {
issueById(id: ID!): Issue
}
type Issue {
id: ID!
}
""".trimIndent(),
runtimeWiring = { wiring ->
data class Issue(val id: String)

val issuesById = listOf(
Issue(
id = "ari:cloud:jira:TEST--67b8ae80-cf1a-4de7-b77c-3f8ff51977b3:issue/10000",
),
).strictAssociateBy { it.id }

wiring
.type("Query") { type ->
type.dataFetcher("issueById") { env ->
issuesById[env.getArgument<String>("id")]
}
}
},
),
Service(
name = "identity",
overallSchema = """
type Query {
userById(id: ID!): User
}
type User {
id: ID!
}
""".trimIndent(),
runtimeWiring = { wiring ->
data class User(val id: String)

val usersById = listOf(
User(
id = "ari:cloud:identity::user/1",
),
).strictAssociateBy { it.id }

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

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

/**
* This class is generated. Do NOT modify.
*
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots
*/
@Suppress("unused")
public class ConditionalHydrationRegexTestSnapshot : TestSnapshot() {
override val calls: List<ExpectedServiceCall> = listOf(
ExpectedServiceCall(
service = "identity",
query = """
| {
| userById(id: "ari:cloud:identity::user/1") {
| __typename
| }
| }
""".trimMargin(),
variables = " {}",
result = """
| {
| "data": {
| "userById": {
| "__typename": "User"
| }
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
),
ExpectedServiceCall(
service = "issues",
query = """
| {
| issueById(id: "ari:cloud:jira:TEST--67b8ae80-cf1a-4de7-b77c-3f8ff51977b3:issue/10000") {
| __typename
| }
| }
""".trimMargin(),
variables = " {}",
result = """
| {
| "data": {
| "issueById": {
| "__typename": "Issue"
| }
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
),
ExpectedServiceCall(
service = "search",
query = """
| {
| search {
| hydration__object__objectId: objectId
| hydration__object__objectId: objectId
| hydration__object__objectId: objectId
| hydration__object__objectId: objectId
| __typename__hydration__object: __typename
| }
| }
""".trimMargin(),
variables = " {}",
result = """
| {
| "data": {
| "search": [
| {
| "hydration__object__objectId": "ari:cloud:jira:TEST--67b8ae80-cf1a-4de7-b77c-3f8ff51977b3:issue/10000",
| "__typename__hydration__object": "SearchResult"
| },
| {
| "hydration__object__objectId": "ari:cloud:identity::user/1",
| "__typename__hydration__object": "SearchResult"
| }
| ]
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
),
)

/**
* ```json
* {
* "data": {
* "search": [
* {
* "object": {
* "__typename": "Issue"
* }
* },
* {
* "object": {
* "__typename": "User"
* }
* }
* ]
* }
* }
* ```
*/
override val result: ExpectedNadelResult = ExpectedNadelResult(
result = """
| {
| "data": {
| "search": [
| {
| "object": {
| "__typename": "Issue"
| }
| },
| {
| "object": {
| "__typename": "User"
| }
| }
| ]
| }
| }
""".trimMargin(),
delayedResults = listOfJsonStrings(
),
)
}

0 comments on commit 3a2626f

Please sign in to comment.