-
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
3 changed files
with
345 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
...t/kotlin/graphql/nadel/tests/hooks/new-batching-conditional-hydration-in-abstract-type.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,37 @@ | ||
package graphql.nadel.tests.hooks | ||
|
||
import graphql.nadel.Nadel | ||
import graphql.nadel.NadelExecutionHints | ||
import graphql.nadel.engine.blueprint.NadelGenericHydrationInstruction | ||
import graphql.nadel.engine.transform.result.json.JsonNode | ||
import graphql.nadel.hooks.NadelExecutionHooks | ||
import graphql.nadel.tests.EngineTestHook | ||
import graphql.nadel.tests.UseHook | ||
|
||
@UseHook | ||
class `new-batching-conditional-hydration-in-abstract-type` : EngineTestHook { | ||
override fun makeExecutionHints(builder: NadelExecutionHints.Builder): NadelExecutionHints.Builder { | ||
return super.makeExecutionHints(builder) | ||
.newBatchHydrationGrouping { true } | ||
} | ||
|
||
override fun makeNadel(builder: Nadel.Builder): Nadel.Builder { | ||
return super.makeNadel(builder) | ||
.executionHooks( | ||
object : NadelExecutionHooks { | ||
override fun <T : NadelGenericHydrationInstruction> getHydrationInstruction( | ||
instructions: List<T>, | ||
sourceId: JsonNode, | ||
userContext: Any?, | ||
): T { | ||
val type = (sourceId.value as String).substringBefore("/") | ||
|
||
return instructions | ||
.first { | ||
it.actorFieldDef.name.startsWith(type, ignoreCase = true) | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
} |
307 changes: 307 additions & 0 deletions
307
...xtures/new hydration/new batching/new-batching-conditional-hydration-in-abstract-type.yml
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,307 @@ | ||
name: "new batching conditional hydration in abstract type" | ||
enabled: true | ||
overallSchema: | ||
# language=GraphQL | ||
monolith: | | ||
type Query { | ||
activity: [IActivity] | ||
issuesByIds(ids: [ID!]!): [Issue!] | ||
commentsByIds(ids: [ID!]!): [Comment!] | ||
} | ||
interface IActivity { | ||
content: [ActivityContent] | ||
} | ||
union ActivityContent = Issue | Comment | ||
type Activity implements IActivity { | ||
id: ID! | ||
content: [ActivityContent] | ||
@hydrated( | ||
service: "monolith" | ||
field: "commentsByIds" | ||
arguments: [ | ||
{name: "ids" value: "$source.contentIds"} | ||
] | ||
) | ||
@hydrated( | ||
service: "monolith" | ||
field: "issuesByIds" | ||
arguments: [ | ||
{name: "ids" value: "$source.contentIds"} | ||
] | ||
) | ||
} | ||
type SingleActivity implements IActivity { | ||
id: ID! | ||
content: [ActivityContent] | ||
@hydrated( | ||
service: "monolith" | ||
field: "issuesByIds" | ||
arguments: [ | ||
{name: "ids" value: "$source.contentId"} | ||
] | ||
) | ||
} | ||
type Issue { | ||
id: ID! | ||
title: String | ||
} | ||
type Comment { | ||
id: ID! | ||
content: String | ||
} | ||
underlyingSchema: | ||
# language=GraphQL | ||
monolith: | | ||
type Query { | ||
activity: [IActivity] | ||
commentsByIds(ids: [ID!]!): [Comment!] | ||
issuesByIds(ids: [ID!]!): [Issue!] | ||
} | ||
interface IActivity { | ||
content: [ActivityContent] | ||
} | ||
union ActivityContent = Issue | Comment | ||
type Activity implements IActivity { | ||
id: ID! | ||
content: [ActivityContent] | ||
contentIds: [ID!] | ||
} | ||
type SingleActivity implements IActivity { | ||
id: ID! | ||
content: [ActivityContent] | ||
contentId: ID! | ||
} | ||
type Issue { | ||
id: ID! | ||
title: String | ||
} | ||
type Comment { | ||
id: ID! | ||
content: String | ||
} | ||
# language=GraphQL | ||
query: | | ||
{ | ||
activity { | ||
content { | ||
__typename | ||
... on Issue { | ||
id | ||
title | ||
} | ||
... on Comment { | ||
id | ||
content | ||
} | ||
} | ||
} | ||
} | ||
variables: { } | ||
serviceCalls: | ||
- serviceName: "monolith" | ||
request: | ||
# language=GraphQL | ||
query: | | ||
{ | ||
activity { | ||
__typename__batch_hydration__content: __typename | ||
... on Activity { | ||
batch_hydration__content__contentIds: contentIds | ||
batch_hydration__content__contentIds: contentIds | ||
} | ||
... on SingleActivity { | ||
batch_hydration__content__contentId: contentId | ||
} | ||
} | ||
} | ||
variables: { } | ||
# language=JSON | ||
response: |- | ||
{ | ||
"data": { | ||
"activity": [ | ||
{ | ||
"__typename__batch_hydration__content": "Activity", | ||
"batch_hydration__content__contentIds": [ | ||
"issue/4000", | ||
"comment/5000", | ||
"comment/6000" | ||
] | ||
}, | ||
{ | ||
"__typename__batch_hydration__content": "SingleActivity", | ||
"batch_hydration__content__contentId": "issue/8080" | ||
}, | ||
{ | ||
"__typename__batch_hydration__content": "Activity", | ||
"batch_hydration__content__contentIds": [ | ||
"comment/1234", | ||
"comment/9001" | ||
] | ||
}, | ||
{ | ||
"__typename__batch_hydration__content": "SingleActivity", | ||
"batch_hydration__content__contentId": "issue/7496" | ||
} | ||
] | ||
}, | ||
"extensions": {} | ||
} | ||
- serviceName: "monolith" | ||
request: | ||
# language=GraphQL | ||
query: | | ||
{ | ||
issuesByIds(ids: ["issue/4000"]) { | ||
__typename | ||
id | ||
batch_hydration__content__id: id | ||
title | ||
} | ||
} | ||
variables: { } | ||
# language=JSON | ||
response: |- | ||
{ | ||
"data": { | ||
"issuesByIds": [ | ||
{ | ||
"__typename": "Issue", | ||
"id": "issue/4000", | ||
"batch_hydration__content__id": "issue/4000", | ||
"title": "Four Thousand" | ||
} | ||
] | ||
}, | ||
"extensions": {} | ||
} | ||
- serviceName: "monolith" | ||
request: | ||
# language=GraphQL | ||
query: | | ||
{ | ||
issuesByIds(ids: ["issue/8080", "issue/7496"]) { | ||
__typename | ||
id | ||
batch_hydration__content__id: id | ||
title | ||
} | ||
} | ||
variables: { } | ||
# language=JSON | ||
response: |- | ||
{ | ||
"data": { | ||
"issuesByIds": [ | ||
{ | ||
"__typename": "Issue", | ||
"id": "issue/7496", | ||
"batch_hydration__content__id": "issue/7496", | ||
"title": "Seven Four Nine Six" | ||
} | ||
] | ||
}, | ||
"extensions": {} | ||
} | ||
- serviceName: "monolith" | ||
request: | ||
# language=GraphQL | ||
query: | | ||
{ | ||
commentsByIds(ids: ["comment/5000", "comment/6000", "comment/1234", "comment/9001"]) { | ||
__typename | ||
content | ||
id | ||
batch_hydration__content__id: id | ||
} | ||
} | ||
variables: { } | ||
# language=JSON | ||
response: |- | ||
{ | ||
"data": { | ||
"commentsByIds": [ | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/5000", | ||
"batch_hydration__content__id": "comment/5000", | ||
"content": "Five Thousand" | ||
}, | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/6000", | ||
"batch_hydration__content__id": "comment/6000", | ||
"content": "Six Thousand" | ||
}, | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/9001", | ||
"batch_hydration__content__id": "comment/9001", | ||
"content": "It's over 9000" | ||
}, | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/1234", | ||
"batch_hydration__content__id": "comment/1234", | ||
"content": "One Two Three Four" | ||
} | ||
] | ||
}, | ||
"extensions": {} | ||
} | ||
# language=JSON | ||
response: | | ||
{ | ||
"data": { | ||
"activity": [ | ||
{ | ||
"content": [ | ||
{ | ||
"__typename": "Issue", | ||
"id": "issue/4000", | ||
"title": "Four Thousand" | ||
}, | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/5000", | ||
"content": "Five Thousand" | ||
}, | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/6000", | ||
"content": "Six Thousand" | ||
} | ||
] | ||
}, | ||
{ | ||
"content": [ | ||
null | ||
] | ||
}, | ||
{ | ||
"content": [ | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/1234", | ||
"content": "One Two Three Four" | ||
}, | ||
{ | ||
"__typename": "Comment", | ||
"id": "comment/9001", | ||
"content": "It's over 9000" | ||
} | ||
] | ||
}, | ||
{ | ||
"content": [ | ||
{ | ||
"__typename": "Issue", | ||
"id": "issue/7496", | ||
"title": "Seven Four Nine Six" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"errors": [] | ||
} |