Fork me on GitHub
#graphql
<
2017-09-15
>
boubalou15:09:46

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.

hlship16:09:45

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.

boubalou17:09:19

I like the way you think, @U04VDKC4G! 😄

hlship17:09:18

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.

boubalou19:09:20

My approach:

boubalou19:09:11

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})

boubalou19:09:33

In schema:

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

boubalou19:09:54

💥 works wonder.

boubalou19:09:39

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