Replies: 3 comments 2 replies
-
|
Are you able to verify that the custom scalar serialize/deserialization is
being invoked properly? You could try setting a breakpoint there to check.
If it is not, the scalar is not wired up properly. If you see that it is
being invoked, we'd have to look at the data fetcher implementation to
investigate further.
…On Tue, Jan 25, 2022 at 10:40 PM Naeul ***@***.***> wrote:
Hi community!
I'm working on some project where I query data from MySQL (using QueryDSL),
then I want serving this data using dgs framework.
I fell into the problem that I want to keep my entity class have
"java.time.LocalDateTime" type,
and serving this data to my clients.
but failing like below
"Can't serialize value (/summary[0]/eventAt) : Expected something we can
convert to 'java.time.OffsetDateTime' but was 'LocalDateTime'
[image: image]
<https://user-images.githubusercontent.com/24990701/151115208-93349191-6473-4867-a5c2-4a93ec1c13ac.png>
------------------------------
This is my entity class
class Summary @QueryProjection constructor(
val ruleSetId: Long?,
val ruleSetName: String?,
val count: Long,
val eventAt: LocalDateTime
)
------------------------------
This is my schema
type Summary {
ruleSetId: ID
ruleSetName: String
count: Int
eventAt: DateTime
}
------------------------------
scalar DateTime
I added DateTimeScalar class (referenced
https://netflix.github.io/dgs/scalars/)
`
@DgsScalar(name = "DateTime")
class DateTimeScalar : Coercing<LocalDateTime, String> {
@throws <https://github.com/throws>(CoercingSerializeException::class)
override fun serialize(dataFetcherResult: Any): String {
return if (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 {
return LocalDateTime.parse(input.toString(), DateTimeFormatter.ISO_DATE_TIME)
}
@throws(CoercingParseLiteralException::class)
override fun parseLiteral(input: Any): LocalDateTime {
if (input is StringValue) {
return LocalDateTime.parse(input.value, DateTimeFormatter.ISO_DATE_TIME)
}
throw CoercingParseLiteralException("Value is not a valid ISO date time")
}
}
`
—
Reply to this email directly, view it on GitHub
<#844>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXN4KLWLKHJIISWLMH3UX6JPLANCNFSM5M2GT45A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
|
As @srinivasankavitha suggests, looks like the extended scalars were not registered. Have you tried just importing the |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Could you please share your code or some example to reproduce this issue?
That will help us understand how you are setting it up.
…On Wed, Jan 26, 2022 at 10:46 PM Naeul ***@***.***> wrote:
Thank you for quick response !
@srinivasankavitha <https://github.com/srinivasankavitha>
It seems like the scalar serialize / deserialize is not invoked.
I set breakpoints all around the "DateTimeScalar" class, but nothing is
captured.
as @berngp <https://github.com/berngp> suggested,
I understand the "DateTimeScalar" is another way to deal with custom scala
type other than "extended scalars".
So I removed all the code and dependecies about
com.graphql-java:graphql-java-extended-scalars.
But I also tried including extended scalars and used like below,
But this is not working either.
@DgsComponent
class DateTimeScalarRegistration {
@DgsRuntimeWiring
fun addScalar(builder: RuntimeWiring.Builder): RuntimeWiring.Builder {
return builder.scalar(ExtendedScalars.DateTime)
}
}
—
Reply to this email directly, view it on GitHub
<#844 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXMYHXJL3IAN2DAS4NLUYDS4DANCNFSM5M2GT45A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi community!
I'm working on some project where I query data from MySQL (using QueryDSL),
then I want serving this data using dgs framework.
I fell into the problem that I want to keep my entity class have "java.time.LocalDateTime" type,
and serving this data to my clients.
but failing like below
"Can't serialize value (/summary[0]/eventAt) : Expected something we can convert to 'java.time.OffsetDateTime' but was 'LocalDateTime'
This is my dto class
class Summary @QueryProjection constructor(
val ruleSetId: Long?,
val ruleSetName: String?,
val count: Long,
val eventAt: LocalDateTime
)
This is my schema
type Summary {
ruleSetId: ID
ruleSetName: String
count: Int
eventAt: DateTime
}
scalar DateTime
I added DateTimeScalar class (referenced https://netflix.github.io/dgs/scalars/)
`
@DgsScalar(name = "DateTime")
class DateTimeScalar : Coercing<LocalDateTime, String> {
@throws(CoercingSerializeException::class)
override fun serialize(dataFetcherResult: Any): String {
return if (dataFetcherResult is LocalDateTime) {
dataFetcherResult.format(DateTimeFormatter.ISO_DATE_TIME)
} else {
throw CoercingSerializeException("Not a valid DateTime")
}
}
}
`
Beta Was this translation helpful? Give feedback.
All reactions