-
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.
Return partial result on hydration exception (#650)
- Loading branch information
Showing
5 changed files
with
669 additions
and
7 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
146 changes: 146 additions & 0 deletions
146
test/src/test/kotlin/graphql/nadel/tests/next/fixtures/hydration/HydrationThrowsErrorTest.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,146 @@ | ||
package graphql.nadel.tests.next.fixtures.hydration | ||
|
||
import graphql.nadel.Nadel | ||
import graphql.nadel.ServiceExecutionHydrationDetails | ||
import graphql.nadel.ServiceExecutionResult | ||
import graphql.nadel.engine.NadelExecutionContext | ||
import graphql.nadel.engine.NadelServiceExecutionContext | ||
import graphql.nadel.engine.blueprint.NadelOverallExecutionBlueprint | ||
import graphql.nadel.engine.transform.NadelTransform | ||
import graphql.nadel.engine.transform.NadelTransformFieldResult | ||
import graphql.nadel.engine.transform.query.NadelQueryTransformer | ||
import graphql.nadel.engine.transform.result.NadelResultInstruction | ||
import graphql.nadel.engine.transform.result.json.JsonNodes | ||
import graphql.nadel.error.NadelGraphQLErrorException | ||
import graphql.nadel.tests.next.NadelIntegrationTest | ||
import graphql.normalized.ExecutableNormalizedField | ||
|
||
class HydrationThrowsErrorTest : NadelIntegrationTest( | ||
query = """ | ||
query { | ||
issueById(id: "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1") { | ||
id | ||
key | ||
assignee { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
""".trimIndent(), | ||
variables = mapOf(), | ||
services = listOf( | ||
Service( | ||
name = "issues", | ||
overallSchema = """ | ||
type Query { | ||
issueById(id: ID!): Issue | ||
} | ||
type Issue { | ||
id: ID! | ||
key: String | ||
assigneeId: ID @hidden | ||
assignee: User | ||
@hydrated( | ||
service: "identity" | ||
field: "userById" | ||
arguments: [{name: "id", value: "$source.assigneeId"}] | ||
) | ||
} | ||
""".trimIndent(), | ||
runtimeWiring = { wiring -> | ||
data class Issue( | ||
val id: String, | ||
val key: String, | ||
val assigneeId: String? = null, | ||
) | ||
|
||
val issuesById = listOf( | ||
Issue( | ||
id = "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1", | ||
key = "GQLGW-1", | ||
assigneeId = "ari:cloud:identity::user/1", | ||
) | ||
).associateBy { it.id } | ||
|
||
wiring | ||
.type("Query") { type -> | ||
type.dataFetcher("issueById") { | ||
issuesById[it.getArgument("id")] | ||
} | ||
} | ||
}, | ||
), | ||
Service( | ||
name = "identity", | ||
overallSchema = """ | ||
type Query { | ||
userById(id: ID!): User | ||
} | ||
type User { | ||
id: ID! | ||
name: String | ||
} | ||
""".trimIndent(), | ||
runtimeWiring = { wiring -> | ||
}, | ||
), | ||
), | ||
) { | ||
override fun makeNadel(): Nadel.Builder { | ||
return super.makeNadel() | ||
.transforms( | ||
listOf( | ||
ThrowErrorTransform(), | ||
), | ||
) | ||
} | ||
|
||
private class ThrowErrorTransform : NadelTransform<Any> { | ||
override suspend fun isApplicable( | ||
executionContext: NadelExecutionContext, | ||
serviceExecutionContext: NadelServiceExecutionContext, | ||
executionBlueprint: NadelOverallExecutionBlueprint, | ||
services: Map<String, graphql.nadel.Service>, | ||
service: graphql.nadel.Service, | ||
overallField: ExecutableNormalizedField, | ||
hydrationDetails: ServiceExecutionHydrationDetails?, | ||
): Any? { | ||
if (overallField.name == "userById") { | ||
throw Bye() | ||
} | ||
|
||
return null | ||
} | ||
|
||
override suspend fun getResultInstructions( | ||
executionContext: NadelExecutionContext, | ||
serviceExecutionContext: NadelServiceExecutionContext, | ||
executionBlueprint: NadelOverallExecutionBlueprint, | ||
service: graphql.nadel.Service, | ||
overallField: ExecutableNormalizedField, | ||
underlyingParentField: ExecutableNormalizedField?, | ||
result: ServiceExecutionResult, | ||
state: Any, | ||
nodes: JsonNodes, | ||
): List<NadelResultInstruction> { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override suspend fun transformField( | ||
executionContext: NadelExecutionContext, | ||
serviceExecutionContext: NadelServiceExecutionContext, | ||
transformer: NadelQueryTransformer, | ||
executionBlueprint: NadelOverallExecutionBlueprint, | ||
service: graphql.nadel.Service, | ||
field: ExecutableNormalizedField, | ||
state: Any, | ||
): NadelTransformFieldResult { | ||
throw UnsupportedOperationException() | ||
} | ||
} | ||
|
||
class Bye : NadelGraphQLErrorException( | ||
message = "BYE", | ||
) | ||
} |
100 changes: 100 additions & 0 deletions
100
...st/kotlin/graphql/nadel/tests/next/fixtures/hydration/HydrationThrowsErrorTestSnapshot.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,100 @@ | ||
// @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<HydrationThrowsErrorTest>() | ||
} | ||
|
||
/** | ||
* This class is generated. Do NOT modify. | ||
* | ||
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots | ||
*/ | ||
@Suppress("unused") | ||
public class HydrationThrowsErrorTestSnapshot : TestSnapshot() { | ||
override val calls: List<ExpectedServiceCall> = listOf( | ||
ExpectedServiceCall( | ||
service = "issues", | ||
query = """ | ||
| { | ||
| issueById(id: "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1") { | ||
| id | ||
| key | ||
| hydration__assignee__assigneeId: assigneeId | ||
| __typename__hydration__assignee: __typename | ||
| } | ||
| } | ||
""".trimMargin(), | ||
variables = " {}", | ||
result = """ | ||
| { | ||
| "data": { | ||
| "issueById": { | ||
| "id": "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1", | ||
| "key": "GQLGW-1", | ||
| "hydration__assignee__assigneeId": "ari:cloud:identity::user/1", | ||
| "__typename__hydration__assignee": "Issue" | ||
| } | ||
| } | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
), | ||
), | ||
) | ||
|
||
/** | ||
* ```json | ||
* { | ||
* "errors": [ | ||
* { | ||
* "message": "BYE", | ||
* "locations": [], | ||
* "extensions": { | ||
* "classification": "Bye" | ||
* } | ||
* } | ||
* ], | ||
* "data": { | ||
* "issueById": { | ||
* "id": "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1", | ||
* "key": "GQLGW-1", | ||
* "assignee": null | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
override val result: ExpectedNadelResult = ExpectedNadelResult( | ||
result = """ | ||
| { | ||
| "errors": [ | ||
| { | ||
| "message": "BYE", | ||
| "locations": [], | ||
| "extensions": { | ||
| "classification": "Bye" | ||
| } | ||
| } | ||
| ], | ||
| "data": { | ||
| "issueById": { | ||
| "id": "ari:cloud:jira:19b8272f-8d25-4706-adce-8db72305e615:issue/1", | ||
| "key": "GQLGW-1", | ||
| "assignee": null | ||
| } | ||
| } | ||
| } | ||
""".trimMargin(), | ||
delayedResults = listOfJsonStrings( | ||
), | ||
) | ||
} |
Oops, something went wrong.