This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-02-23
Channels
- # announcements (18)
- # beginners (26)
- # calva (12)
- # cider (43)
- # cljdoc (4)
- # clojure (38)
- # clojure-europe (11)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-sweden (2)
- # clojure-uk (4)
- # cursive (17)
- # data-science (4)
- # datalevin (2)
- # datomic (3)
- # emacs (10)
- # ghostwheel (4)
- # graphql (11)
- # honeysql (1)
- # hyperfiddle (7)
- # introduce-yourself (1)
- # malli (23)
- # nrepl (11)
- # overtone (1)
- # pathom (9)
- # pedestal (2)
- # polylith (1)
- # portal (3)
- # reitit (1)
- # shadow-cljs (12)
- # timbre (4)
- # vim (2)
- # xtdb (4)
In lacinia I want to define a custom type/scalar which is represented as a two-element vector/array (tupel):
:Something
{:fields
{:values {:type (list (non-null :Tupel))}
;...
}}
But when resolving values
I try to return something like [[1 2] [3 4]]
which results in a GraphQL error: "Field resolver returned a collection of values, expected only a single value."
. Could that be fixed by some sort of custom field resolver?This rings a bell. I had this issue before. The workaround is to define a scalar type (which you already have, Tuple
), make your resolver return a wrapper map with a single key, and add type serializer that accesses that key
Custom type definition that has a serializer simply accessing a key: https://gitlab.com/arbetsformedlingen/taxonomy-dev/backend/jobtech-taxonomy-api/-/blob/main/src/clj/jobtech_taxonomy_api/db/graphql/changelog.clj?ref_type=heads#L265
And the wrapper that wraps a value, used in the resolver: https://gitlab.com/arbetsformedlingen/taxonomy-dev/backend/jobtech-taxonomy-api/-/blob/main/src/clj/jobtech_taxonomy_api/db/graphql/changelog.clj?ref_type=heads#L221
Thanks for the swift reply, @U47G49KHQ. Yes, wrapping in a map was my workaround but it doesn't look all that pretty. I thought there might be an other approach? @U04VDKC4G any ideas or ways to teach lacinia a new trick?
Lacinia execution involves a deep-merge step which takes multiple resolver results and combines them into a single value. This code is not aware of graphql types, so it cannot know that your vector is meant to be a tuple rather than a collection
Note your custom scalar can decode to a vector , but your resolvers must return something non-vector for the encoder