-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧑💻 Innføre full støtte for UUID i graphql-kode
- Loading branch information
Showing
30 changed files
with
217 additions
and
143 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
46 changes: 46 additions & 0 deletions
46
spesialist-api/src/main/kotlin/no/nav/helse/spesialist/api/graphql/SchemaGeneratorHooks.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,46 @@ | ||
package no.nav.helse.spesialist.api.graphql | ||
|
||
import com.expediagroup.graphql.generator.hooks.SchemaGeneratorHooks | ||
import graphql.GraphQLContext | ||
import graphql.execution.CoercedVariables | ||
import graphql.language.Value | ||
import graphql.schema.Coercing | ||
import graphql.schema.GraphQLScalarType | ||
import graphql.schema.GraphQLType | ||
import java.util.Locale | ||
import java.util.UUID | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.KType | ||
|
||
/** | ||
* Støttekode for å kunne bruke UUID som type, i stedet for å måtte ha den som String. | ||
*/ | ||
internal val schemaGeneratorHooks = object : SchemaGeneratorHooks { | ||
override fun willGenerateGraphQLType(type: KType): GraphQLType? = when (type.classifier as? KClass<*>) { | ||
UUID::class -> graphQLUUID | ||
else -> null | ||
} | ||
} | ||
|
||
private val graphQLUUID: GraphQLScalarType = GraphQLScalarType.newScalar() | ||
.name(UUID::class.simpleName) | ||
.description(UUID::class.toString()) | ||
.coercing(UuidCoercing) | ||
.build() | ||
|
||
private object UuidCoercing : Coercing<UUID, String> { | ||
|
||
override fun serialize(dataFetcherResult: Any, graphQLContext: GraphQLContext, locale: Locale) = | ||
dataFetcherResult.toString() | ||
|
||
override fun parseValue(input: Any, graphQLContext: GraphQLContext, locale: Locale): UUID = | ||
UUID.fromString(serialize(input, graphQLContext, locale)) | ||
|
||
override fun parseLiteral( | ||
input: Value<*>, | ||
variables: CoercedVariables, | ||
graphQLContext: GraphQLContext, | ||
locale: Locale, | ||
): UUID = | ||
UUID.fromString(serialize(input, graphQLContext, locale)) | ||
} |
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.