Fork me on GitHub
#graphql
<
2023-09-13
>
steven kent17:09:18

This was going to be a Lacinia question about implementing union types (https://lacinia.readthedocs.io/en/latest/unions.html), but it seems like I resolved it. So, I'm putting a short description here in case it might help someone. First of all, thanks for the work on Lacinia & the documentation for it. I am using hashmaps as return types for my resolvers. To get a union type working, I did these things: 1. Add a :unions key to my EDN schema. This names the union type and details which concrete types are involved in the union, via the members key & vector 2. For whichever operations in my schema which will be returning that union type, I updated the type for that operation to use the newly created union type 3. You have to explicitly indicate to the relevant resolvers which concrete type (that exists in the union) is being returned. I did this in the relevant resolvers by using com.walmartlabs.lacinia.schema/tag-with-type, ns aliased as schema. For example, if the concrete type being returned is :Product, (schema/tag-with-type <HASHMAP-BEING-RETURNED> :Product). https://lacinia.readthedocs.io/en/latest/resolve/type-tags.html is useful for this step.