teamwalnut / graphql-ppx

GraphQL language primitives for ReScript/ReasonML written in ReasonML
https://graphql-ppx.com
MIT License
258 stars 53 forks source link

Generate handy string-related helpers for graphql `Enum` types #134

Closed develop7 closed 4 years ago

develop7 commented 4 years ago

In order to avoid end users writing to&from string boilerplate helpers (which are essential when, for instance, populating a <select> with enum members) these should be generated by the ppx.

Given the following enum

enum Foo {
    "Bar comment"
    Bar
    "Qux comment"
    Qux
}

we have following type generated

type foo = [ `Bar | `Qux ]

and in order to populate selects with the values of that type we need to have them converted to strings

let string_of_Foo = (foo: foo) => switch (foo ){
| `Bar => "Bar"
| `Qux => "Qux"
}

and other way around as well

let Foo_of_string = s => switch (s) {
| "Bar" => `Bar
| "Qux" => `Qux
}

I'd love to have these generated for me; or have @bs.deriving jsConverter cast upon.

EDIT: removed irrelevant request

jsiebern commented 4 years ago

As discussed on Discord: I like the idea and we're gonna put this in.

Just a note on your last remark (comment function): I believe this is too opinionated for an abstract ppx like this. Think the following cases:

Generally I believe this should be an implementation detail, esp. because most of the time these comments are used as developer information (inspecting the schema) rather than storing user facing values.

develop7 commented 4 years ago

Generally I believe this should be an implementation detail, esp. because most of the time these comments are used as developer information (inspecting the schema) rather than storing user facing values.

good point, that belongs to the l10n, it's just me trying to do a shortcut prototyping the app

jfrolich commented 4 years ago

Sorry for being lazy and not following up on this! It looks like this functionality is coming natively to BuckleScript, so I guess we don't need this anymore.