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

**URL:** <https://discourse.elm-lang.org/t/could-you-achieve-type-safety-between-front-end-and-back-end-for-flags-with-elm-graphql/7069>\
**Category:** Learn\
**Created:** [March 9, 2021, 9:02pm UTC](https://discourse.elm-lang.org/t/could-you-achieve-type-safety-between-front-end-and-back-end-for-flags-with-elm-graphql/7069 "2021-03-09T21:02:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![neurodynamic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/neurodynamic/32/984_2.png) [@neurodynamic](https://discourse.elm-lang.org/u/neurodynamic)\
**Post date:** [March 9, 2021, 9:02pm UTC](https://discourse.elm-lang.org/t/could-you-achieve-type-safety-between-front-end-and-back-end-for-flags-with-elm-graphql/7069/1 "2021-03-09T21:02:52Z")

</div>

I’ve been making a lot of use out of [elm-graphql](https://package.elm-lang.org/packages/dillonkearns/elm-graphql/latest/) for type-safety with API requests in an app I’m working on, and I’ve recently started experimenting with [elm-ts-interop](https://elm-ts-interop.com) 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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [March 19, 2021, 9:03pm UTC](https://discourse.elm-lang.org/t/could-you-achieve-type-safety-between-front-end-and-back-end-for-flags-with-elm-graphql/7069/2 "2021-03-19T21:03:25Z")

</div>

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