-
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
4 changed files
with
20 additions
and
92 deletions.
There are no files selected for viewing
76 changes: 0 additions & 76 deletions
76
spring-graphql-rsocket-kotlin-co/src/main/kotlin/com/example/demo/ValidationConfig.kt
This file was deleted.
Oops, something went wrong.
22 changes: 16 additions & 6 deletions
22
...hql-rsocket-kotlin-co/src/main/kotlin/com/example/demo/gql/scalars/LocalDateTimeScalar.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,33 +1,43 @@ | ||
package com.example.demo.gql.scalars | ||
|
||
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.CoercingParseValueException | ||
import graphql.schema.CoercingSerializeException | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
import java.util.* | ||
|
||
class LocalDateTimeScalar : Coercing<LocalDateTime, String> { | ||
@Throws(CoercingSerializeException::class) | ||
override fun serialize(dataFetcherResult: Any): String? { | ||
override fun serialize(dataFetcherResult: Any, graphQLContext: GraphQLContext, locale: Locale): String? { | ||
return when (dataFetcherResult) { | ||
is LocalDateTime -> dataFetcherResult.format(DateTimeFormatter.ISO_DATE_TIME) | ||
else -> throw CoercingSerializeException("Not a valid DateTime") | ||
} | ||
} | ||
|
||
@Throws(CoercingParseValueException::class) | ||
override fun parseValue(input: Any): LocalDateTime { | ||
override fun parseValue(input: Any, graphQLContext: GraphQLContext, locale: Locale): LocalDateTime { | ||
return LocalDateTime.parse(input.toString(), DateTimeFormatter.ISO_DATE_TIME) | ||
} | ||
|
||
@Throws(CoercingParseLiteralException::class) | ||
override fun parseLiteral(input: Any): LocalDateTime { | ||
override fun parseLiteral( | ||
input: Value<*>, | ||
variables: CoercedVariables, | ||
graphQLContext: GraphQLContext, | ||
locale: Locale | ||
): LocalDateTime { | ||
when (input) { | ||
is StringValue -> return LocalDateTime.parse(input.value, DateTimeFormatter.ISO_DATE_TIME) | ||
else -> throw CoercingParseLiteralException("Value is not a valid ISO date time") | ||
} | ||
} | ||
|
||
override fun valueToLiteral(input: Any, graphQLContext: GraphQLContext, locale: Locale): Value<*> { | ||
return StringValue(input.toString()) | ||
} | ||
|
||
} |
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