1. Handling of relationships (with user defined phantom types)
2. Building query and decoder simultaneously
In regards to code gen, as I see it, the only thing needing to be generated would be the Resource representation. Many people argue that decoders and encoders are the pain point, but I think with a good query builder API this pain is alleviated. I was unable to come up with a general API myself (hence the domain specific library I made), so I am interested in your efforts.
Would love to chat! I'm usually on slack + the sf meetup.
I came upon the idea that the client (that's you) will provide a type alias for each resource's attributes (and perhaps other crucial information), and I could generate code that would retrieve resources of those types. Generating code also allows the tool to create JSON encoders and decoders, a common pain point.
1. Handling of relationships (with user defined phantom types)
In regards to code gen, as I see it, the only thing needing to be generated would be the Resource representation.
Many people argue that decoders and encoders are the pain point, but I think with a good query builder API this pain is alleviated. I was unable to come up with a general API myself (hence the domain specific library I made), so I am interested in your efforts.
Would love to chat! I'm usually on slack + the sf meetup.
I've been doing something very similar and it is proving very worthwhile, so I would encourage you to pursue this.
For Elm, I output one (big) file called Model.elm, that gives me the data model mapped onto Elm, and encoders and decoders for it. Then for each grouping of endpoints (each service implemented in Java provides the grouping) I generate one Elm file that implements the Http logic for the service.
Each service requires a set of callback functions to be passed in - one for each endpoint, plus one for each endpoint when it results in an error, plus a default error handler for cases when the endpoint specific error handler doesn't process the error.
Another possibility would be to use an API description meta-data such as Swagger. A Swagger codegen for Elm could easily output something useable.
I think Elm will be well suited to writing code generators - in a manner similar to how it 'codegens' Html. You can design a set of functions for constructing the component parts of the output language you are working with. Elm is good for doing complex AST manipulation and it can be set up to guarantee correctly formed output. Code generation of Elm in Elm will be a mind bender.
For Elm, I output one (big) file called Model.elm, that gives me the data model mapped onto Elm, and encoders and decoders for it. Then for each grouping of endpoints (each service implemented in Java provides the grouping) I generate one Elm file that implements the Http logic for the service.I've come to the same file structure, because JSON API allows for included resources. For example, articles can include their author an vice versa, which means those decoders have to be defined in a common file. I'm trying to wrap them in one module per resource, though.
Then I could represent the data models as HAL or JSON-LD
Elm does not support phantom types (to my understanding). What do you have in mind here? How can phantom types represent relationships?
Interesting. I take it you are generating resource definitions from the Postgres schema. In my library, the resource's representation (as a type alias of a record of attributes) is the input to the code gen, the one thing that is not generated.
And I think one might as well generate encoders and decoders, at least if not overridden, so that the code one must write by hand (those type aliases) is as minimal as possible.