Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Custom decoder functions for built-in types? #157

Open
1 of 5 tasks
sgrove opened this issue Nov 21, 2018 · 2 comments
Open
1 of 5 tasks

Custom decoder functions for built-in types? #157

sgrove opened this issue Nov 21, 2018 · 2 comments

Comments

@sgrove
Copy link

sgrove commented Nov 21, 2018

Issue Labels

  • has-reproduction
  • feature
  • docs
  • blocking
  • good first issue

So this might be a bit strange, but it would possibly be nice to be able to define custom decoders for combination of ObjectType.fieldName.

Consider the code below:

let timestampJson = Js.Json.decodeString(timestamp);

      let date =
        switch (timestampJson) {
        | Some(stamp) => Js.Date.fromString(stamp)
        | None => Js.Date.make()
        };

Basically, I know there is a timestamp of DateTime which is represented as Json.t (string). It'd be really nice to be able to annotate my client with additional decoder information so that I automatically get an option(Js.Date.t).

Something akin to this perhaps:

let customDecoders = [ObjectField("User", "createdAt", parseDate)];

Then it'd be fairly easy to annotate all the types/fields that are date times, and remove the need for conversions everywhere at usage sites.

@Gregoirevda
Copy link
Contributor

This thread tries to solve the same problem in JS.

Easiest solution seems to be a link, like this one (written in reason or bindings to it)

@fakenickels
Copy link
Contributor

fakenickels commented Dec 13, 2018

This is interesting, but I feel like it's more https://github.com/mhallin/graphql_ppx related than reason-apollo

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants