js-composedb icon indicating copy to clipboard operation
js-composedb copied to clipboard

Ensure DateTime scalar inputs are converted to string

Open PaulLeCam opened this issue 1 year ago • 5 comments

Description

The DateTime scalar from the graphql-scalars library converts inputs to JS Date objects rather than strings as expected. There is a PR already open to fix the issue but we should address it directly here in the meantime.

Technical Information

The PR to fix the issue in graphql-scalars could a good solution to look into, implementing similar changes in our @composedb/graphql-scalars package.

PaulLeCam avatar Oct 28 '22 09:10 PaulLeCam

@PaulLeCam

It seems like @composedb/graphql-scalars is implemented as a simple pass through of the scalar types defined in the graphql-scalars package.

The PR you referenced is fixing an issue in the serialize function of the datetime scalar which that package is exporting

I could implement a custom definition for the datetime scalar type (to use temporarily in place of the one being exported by graphql-scalars) but that may be overkill for a package which is currently very simple - especially with a PR pending with a fix.

Happy to work on a temporary solution but wanted to get your feedback before proceeding.

morozj01 avatar Oct 31 '22 21:10 morozj01

Shouldn't dates get converted into number types, or ideally to native date objects in the underlying db, so that range queries can work effectively?

stbrody avatar Oct 31 '22 22:10 stbrody

I guess the problem is that JSON doesn't have a native encoding for dates. Sigh, this was one of the reasons that MongoDB's BSON added extra types beyond the base supported in JSON. We might want to consider defining a JSON-compatible serialization format for dates so that Ceramic nodes can actually treat dates like dates

stbrody avatar Oct 31 '22 22:10 stbrody

Exactly - ceramic is importing a library which is supposed to serialize dates into strings already but there is a bug where it is not being done.

They have a PR open with a potential fix but it has been inactive for a while

https://github.com/ceramicstudio/js-composedb/pull/54 This could be a temporary solution if you think it's not worth waiting for them to merge that PR @stbrody @PaulLeCam

morozj01 avatar Nov 07 '22 02:11 morozj01

Thanks @morozj01, I left some comments on your PR.

PaulLeCam avatar Nov 07 '22 10:11 PaulLeCam