-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[generator] add IDValueUnboxer for correctly serializing ID value cla…
…ss (#1385) Since `ID` is a value class, it may be represented at runtime as a wrapper or directly as underlying type. Due to the generic nature of the query processing logic we *always* end up with up a wrapper type when resolving the field value. As a result, in order to ensure that underlying scalar value is correctly serialized, we need to explicitly unwrap it by registering `IDValueUnboxer` with your GraphQL instance. ```kotlin // registering custom value unboxer val graphQL = GraphQL.newGraphQL(graphQLSchema) .valueUnboxer(IDValueUnboxer()) .build() ``` `IDValueUnboxer` is automatically registered by `graphql-kotlin-spring-server`.
- Loading branch information
Dariusz Kuc
authored
Mar 9, 2022
1 parent
5affacd
commit 0288c92
Showing
16 changed files
with
289 additions
and
63 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
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
17 changes: 17 additions & 0 deletions
17
...ma-generator/src/main/kotlin/com/expediagroup/graphql/generator/scalars/IDValueUnboxer.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,17 @@ | ||
package com.expediagroup.graphql.generator.scalars | ||
|
||
import graphql.execution.ValueUnboxer | ||
|
||
/** | ||
* ID is a value class which may be represented at runtime as wrapper or directly as underlying type. | ||
* | ||
* We need to explicitly unwrap it as due to the generic nature of the query processing logic we always end up | ||
* with up a wrapper type when resolving the field value. | ||
*/ | ||
open class IDValueUnboxer : ValueUnboxer { | ||
override fun unbox(`object`: Any?): Any? = if (`object` is ID) { | ||
`object`.value | ||
} else { | ||
`object` | ||
} | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.