-
Notifications
You must be signed in to change notification settings - Fork 21
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
17 changed files
with
167 additions
and
110 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
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
52 changes: 52 additions & 0 deletions
52
dgs-kotlin-co/src/main/kotlin/com/example/demo/gql/scalar/UUIDScalar.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,52 @@ | ||
package com.example.demo.gql.scalars | ||
|
||
import com.netflix.graphql.dgs.DgsScalar | ||
import graphql.GraphQLContext | ||
import graphql.execution.CoercedVariables | ||
import graphql.language.StringValue | ||
import graphql.language.Value | ||
import graphql.schema.Coercing | ||
import graphql.schema.CoercingParseLiteralException | ||
import graphql.schema.CoercingSerializeException | ||
import java.util.* | ||
|
||
@DgsScalar(name = "UUID") | ||
class UUIDScalar : Coercing<UUID, String> { | ||
|
||
override fun valueToLiteral( | ||
input: Any, | ||
graphQLContext: GraphQLContext, | ||
locale: Locale | ||
): Value<*> = StringValue.of(input.toString()) | ||
|
||
override fun parseLiteral( | ||
input: Value<*>, | ||
variables: CoercedVariables, | ||
graphQLContext: GraphQLContext, | ||
locale: Locale | ||
): UUID? { | ||
if (input is StringValue) { | ||
return UUID.fromString(input.value); | ||
} | ||
|
||
throw CoercingParseLiteralException("Value is not a valid UUID string"); | ||
} | ||
|
||
override fun parseValue( | ||
input: Any, | ||
graphQLContext: GraphQLContext, | ||
locale: Locale | ||
): UUID? = UUID.fromString(input.toString()) | ||
|
||
override fun serialize( | ||
dataFetcherResult: Any, | ||
graphQLContext: GraphQLContext, | ||
locale: Locale | ||
): String? { | ||
if (dataFetcherResult is UUID) { | ||
return dataFetcherResult.toString(); | ||
} | ||
|
||
throw CoercingSerializeException("Not a valid UUID"); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
dgs-kotlin-co/src/main/kotlin/com/example/demo/service/AuthorNotFoundException.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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package com.example.demo.service | ||
|
||
class AuthorNotFoundException(id: String) : RuntimeException("Author: $id was not found.") | ||
import java.util.* | ||
|
||
class AuthorNotFoundException(id: UUID) : RuntimeException("Author: $id was not found.") | ||
|
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
4 changes: 3 additions & 1 deletion
4
dgs-kotlin-co/src/main/kotlin/com/example/demo/service/PostNotFoundException.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package com.example.demo.service | ||
|
||
class PostNotFoundException(id: String) : RuntimeException("Post: $id was not found.") | ||
import java.util.UUID | ||
|
||
class PostNotFoundException(id: UUID) : RuntimeException("Post: $id was not found.") |
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.