-
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 conditional ATI test using Regex
- Loading branch information
Showing
3 changed files
with
286 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
133 changes: 133 additions & 0 deletions
133
.../graphql/nadel/tests/next/fixtures/hydration/conditional/ConditionalHydrationRegexTest.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,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")] | ||
} | ||
} | ||
}, | ||
), | ||
) | ||
) |
145 changes: 145 additions & 0 deletions
145
.../nadel/tests/next/fixtures/hydration/conditional/ConditionalHydrationRegexTestSnapshot.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,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( | ||
), | ||
) | ||
} |