-
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
29 changed files
with
290 additions
and
240 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
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
34 changes: 19 additions & 15 deletions
34
dgs-kotlin/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,43 +1,47 @@ | ||
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.CoercingParseValueException | ||
import graphql.schema.CoercingSerializeException | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
|
||
//@DgsComponent | ||
//class DateTimeScalar { | ||
// @DgsRuntimeWiring | ||
// fun addScalar(builder: RuntimeWiring.Builder): RuntimeWiring.Builder { | ||
// return builder.scalar(ExtendedScalars.DateTime) | ||
// } | ||
//} | ||
import java.util.* | ||
|
||
@DgsScalar(name = "LocalDateTime") | ||
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 when (input) { | ||
is String -> StringValue.newStringValue(input).build() | ||
else -> throw CoercingParseValueException("Value is not a string") | ||
} | ||
} | ||
} |
Oops, something went wrong.