Skip to content

Type resolvers for union and interface types #283

Description

@mmmdreg

I have my first lacinia app in production and am enjoying it so far so thanks for the hard work up front.

Currently to resolve union and interface types correctly, we have to tag-with-type or use records. I find these a bit troublesome especially if the type to be tagged is nested somewhere in the data I am returning.

I like to keep my graphql resolvers as a very thin layer on top of business logic which may or may not be shared by other non-graphql access methods. In the above case of nested data structures, I either have to tag it where the child value is created, polluting the namespace with lacinia specific code, or in the resolver, do some cumbersome unwrapping, tagging, and wrapping.

I’ve written several graphql services in javascript before and one thing I liked there was being able to define a resolveType function (https://graphql.org/graphql-js/type/#graphqluniontype). This is literally a function that takes the value and returns some type identifier, eg based on some attribute of a map. This could perhaps be implemented as additional placeholder attributes in the schema.edn and nicely prevents graphql requirements to leak into other code.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions