hatellla
hatellla

Reputation: 5132

Unable to serialise AWSDate from Elasticsearch

I'm building an AppSync project using AWS elasticsearch service as my db, and got this error when querying:

"Can't serialize value (/getUsers/created_at) : Unable to serialize 2020-01-18T07:36:13 as a valid DateTime Object."

This happens when I get a User object which looks like this:

type Users {
  id: String!
  name: String!
  description: String
  created_at: AWSDateTime
  updated_at: AWSDateTime
  logged_in: AWSDateTime
}

The data stored in elasticsearch is of string type and of this format: 2020-01-18T07:36:13.

I saw similar posts of this sort but can't find any solution for it. So, is there any way, I should deserialize it to AWSDataTime in my response mapping template or should I store in some date format in elasticsearch.

One solution I got from this post Unable to serialise AWSDate from RDS in AppSync response mapping template is that to make the type of the date as String. But then, what's the use of AWSDateTime at all.

Upvotes: 0

Views: 959

Answers (1)

Ionut Trestian
Ionut Trestian

Reputation: 5751

Looking at the AWS AppSync docs, it seems that the time zone offset is compulsory for this scalar (AWSDateTime that is). From your example, it seems this is missing since there is nothing after the seconds field. You could try appending the time zone offset yourself in which case, it will serialize correctly.

Upvotes: 2

Related Questions