Skip to content

Commit

Permalink
Fork hydration tests (#478)
Browse files Browse the repository at this point in the history
* Fork hydration tests

* Fix duplicated test for new code
  • Loading branch information
gnawf authored Dec 10, 2023
1 parent b03759b commit 194764f
Show file tree
Hide file tree
Showing 134 changed files with 20,632 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/src/test/kotlin/graphql/nadel/tests/EngineTestHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,42 @@ private val hooksPackage: String = join(
internal fun getTestHook(fixture: TestFixture): EngineTestHook? {
require(Util.validated) { "Tests hooks are not valid" }

val className = when (val name = fixture.name) {
"new transformer on hydration fields",
"new can generate legacy operation name on batch hydration for specific service",
"new can generate legacy operation name on batch hydration",
"new can generate legacy operation name on hydration",
"new batching of hydration list with partition",
"new batch polymorphic hydration where only one type is queried",
"new batch polymorphic hydration",
"new batch polymorphic hydration actor fields are in the same service",
"new batch polymorphic hydration when hook returns null",
"new batch polymorphic hydration with lots of renames",
"new batch polymorphic hydration with unions",
"new solitary polymorphic hydration when hook returns null",
"new batch polymorphic hydration with interfaces",
"new solitary polymorphic hydration",
"new batch polymorphic hydration with rename",
"new batch polymorphic hydration when hook returns null 1",
"new batch polymorphic hydration actor fields are in the same service return types implement same interface",
"new complex-identified-by-with-rename",
"new new batching single source id",
"new new batching multiple source ids going to different services",
->
name.removePrefix("new ")
else -> name
}.toSlug()

val hookClass = try {
Class.forName(
join(hooksPackage, fixture.name.toSlug(), separator = "."),
join(hooksPackage, className, separator = "."),
)
} catch (e: ClassNotFoundException) {
println("No hook class found: ${e.message}")
return null
}

return hookClass.newInstance() as EngineTestHook
return hookClass.declaredConstructors.single().newInstance() as EngineTestHook
}

private object Util {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
name: "new complex identified by doesnt use all input fields in the inputIdentifiedBy argument"
enabled: true
overallSchema:
Activity: |
type Query {
activities: [Activity]
}
type Activity {
id: ID
issue: Issue @hydrated(
service: "Issue"
field: "issues"
arguments: [{name: "issuesInput" value: "$source.context.issueHydrationInput"}]
inputIdentifiedBy: [
{sourceId: "context.issueHydrationInput.id" resultId: "issueId"}
]
)
}
Issue: |
type Query {
issues(issuesInput: IssueInput!): [Issue]
}
type Issue {
issueId: ID
description: String
}
input IssueInput {
id: ID!
site: ID!
}
underlyingSchema:
Activity: |
type Query {
activities: [Activity]
}
type Activity {
id: ID
context: HydrationContext
}
type HydrationContext {
issueHydrationInput: IssueHydrationInput
}
type IssueHydrationInput {
id: ID!
site: ID!
}
Issue: |
type Query {
issues(issuesInput: IssueInput!): [Issue]
}
type Issue {
issueId: ID
description: String
}
input IssueInput {
id: ID!
site: ID!
}
query: |
query {
activities {
id
issue {
issueId
description
}
}
}
variables: { }
serviceCalls:
- serviceName: "Activity"
request:
query: |
{
activities {
__typename__batch_hydration__issue: __typename
batch_hydration__issue__context: context {
issueHydrationInput {
id
}
}
batch_hydration__issue__context: context {
issueHydrationInput {
site
}
}
id
}
}
variables: { }
# language=JSON
response: |-
{
"data": {
"activities": [
{
"__typename__batch_hydration__issue": "Activity",
"batch_hydration__issue__context": {
"issueHydrationInput": {
"id": "ISSUE-0",
"site": "CLOUD-0"
}
},
"id": "ACTIVITY-0"
},
{
"__typename__batch_hydration__issue": "Activity",
"batch_hydration__issue__context": {
"issueHydrationInput": {
"id": "ISSUE-1",
"site": "CLOUD-0"
}
},
"id": "ACTIVITY-1"
},
{
"__typename__batch_hydration__issue": "Activity",
"batch_hydration__issue__context": {
"issueHydrationInput": {
"id": "ISSUE-2",
"site": "CLOUD-0"
}
},
"id": "ACTIVITY-2"
},
{
"__typename__batch_hydration__issue": "Activity",
"batch_hydration__issue__context": {
"issueHydrationInput": {
"id": "ISSUE-3",
"site": "CLOUD-0"
}
},
"id": "ACTIVITY-3"
}
]
},
"extensions": {}
}
- serviceName: "Issue"
request:
query: |
{
issues(issuesInput: [{id : "ISSUE-0", site : "CLOUD-0"}, {id : "ISSUE-1", site : "CLOUD-0"}, {id : "ISSUE-2", site : "CLOUD-0"}, {id : "ISSUE-3", site : "CLOUD-0"}]) {
description
issueId
batch_hydration__issue__issueId: issueId
}
}
variables: { }
# language=JSON
response: |-
{
"data": {
"issues": [
{
"batch_hydration__issue__issueId": "ISSUE-0",
"issueId": "ISSUE-0",
"description": "fix A"
},
{
"batch_hydration__issue__issueId": "ISSUE-1",
"issueId": "ISSUE-1",
"description": "fix B"
},
{
"batch_hydration__issue__issueId": "ISSUE-2",
"issueId": "ISSUE-2",
"description": "fix C"
},
{
"batch_hydration__issue__issueId": "ISSUE-3",
"issueId": "ISSUE-3",
"description": "fix D"
}
]
},
"extensions": {}
}
# language=JSON
response: |-
{
"data": {
"activities": [
{
"id": "ACTIVITY-0",
"issue": {
"issueId": "ISSUE-0",
"description": "fix A"
}
},
{
"id": "ACTIVITY-1",
"issue": {
"issueId": "ISSUE-1",
"description": "fix B"
}
},
{
"id": "ACTIVITY-2",
"issue": {
"issueId": "ISSUE-2",
"description": "fix C"
}
},
{
"id": "ACTIVITY-3",
"issue": {
"issueId": "ISSUE-3",
"description": "fix D"
}
}
]
},
"errors": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: "new complex identified by hydration batching returns null batch"
enabled: true
overallSchema:
service2: |
type Query {
barsById(id: [ID]): [Bar]
}
type Bar {
id: ID
name: String
}
service1: |
type Query {
foo: Foo
}
type Foo {
id: ID
bar: [Bar] @hydrated(
service: "service2"
field: "barsById"
arguments: [{name: "id" value: "$source.barId"}]
inputIdentifiedBy: [{sourceId: "barId" resultId: "id"}]
)
}
underlyingSchema:
service2: |
type Bar {
id: ID
name: String
}
type Query {
barsById(id: [ID]): [Bar]
}
service1: |
type Foo {
barId: [ID]
id: ID
}
type Query {
foo: Foo
}
query: |
query {
foo {
bar {
name
}
}
}
variables: { }
serviceCalls:
- serviceName: "service1"
request:
query: |
query {
foo {
__typename__batch_hydration__bar: __typename
batch_hydration__bar__barId: barId
}
}
variables: { }
# language=JSON
response: |-
{
"data": {
"foo": {
"__typename__batch_hydration__bar": "Foo",
"batch_hydration__bar__barId": [
"barId1",
"barId2",
"barId3"
]
}
},
"extensions": {}
}
- serviceName: "service2"
request:
query: |
query {
barsById(id: ["barId1", "barId2", "barId3"]) {
batch_hydration__bar__id: id
name
}
}
variables: { }
# language=JSON
response: |-
{
"extensions": {}
}
# language=JSON
response: |-
{
"data": {
"foo": {
"bar": [
null,
null,
null
]
}
},
"extensions": {}
}
Loading

0 comments on commit 194764f

Please sign in to comment.