Fork me on GitHub

In the lacinia schema (EDN file), is there a way to have enums as already defined keywords in the code somewhere and import them in the schema? I feel like it’s so error prone to have a text mapping for enums. In our schema, we have a lot of values for multiple enums and it feel really cumbersome.


Well, you can specify enums as strings, keywords, or symbols --- internally they are always represented as keywords. Remember that you read the EDN file, then compile it ... it is totally expected that you could assoc-in additional data between those steps.


I like the way you think, @U04VDKC4G! 😄


I think it's good design, but it was already in place before I did any work on Lacinia. @U3DJ4E4C9 should be thanked for establishing for the schema-as-EDN approach, which just works so well with the Clojure ethic and ecosystem.


My approach:


Added a new util almost copied from lacinia-util/attach-resolvers which gives:

(edn-utils/replace-enum-values {:resolve-tension-trend-values capabilities-service/tension-trends})


In schema:

:tensionTrend             {:description    "The different tension trend possible values for a tension capability."
                             :resolve-values :resolve-tension-trend-values}


💥 works wonder.


It could even be slipped in lacinia directly if you want me to propose a PR that could evolve on your side afterward.