Could you achieve type-safety between front-end and back-end for flags with elm-graphql?

I’ve been making a lot of use out of elm-graphql for type-safety with API requests in an app I’m working on, and I’ve recently started experimenting with elm-ts-interop for type-safety within my Elm front-end and my JS front-end code.

In doing this, I realized that while the type-safety for ports with elm-ts-interop is really useful, the type-safety for flags feels like there’s one more layer I’d like to have to be as confident as possible in my code. With elm-ts-interop, my flags are type-safe within the front-end code, but not between the front-end and back-end code like with elm-graphql and API requests.

My flags are just embedded in the HTML when the page loads, parsed, and then passed to the Elm app from there. No guarantee that the back-end sent a compatible bunch of JSON.

In thinking about this, it occurred to me that I hadn’t considered: has anyone tried using elm-graphql to enforce type-safety for flags? That is, embedding a graphql response in the initial page-load’s HTML and then decoding the flags within Elm with generated elm-graphql code? If not, is there any reason that couldn’t work?

If not, I think I might take a stab at it, but I figured I’d ask the community first to see if anyone’s tried already or knows of a reason it wouldn’t be feasible.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.