enums defined outside of graphql layer #2769
Unanswered
peterkuykendall
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'd like some help understanding how to use enums that are defined outside of the graphql types.
To keep a clean architecture, I'm having enums defined off the root level (e.g., dtos, models, constants, enums), graphql is in one directory off of the root (schemas, resolvers, types) and the business logic (internals, pkg, etc) is off of root in other directories. Scalars work well, but enums don't because in order for the enum to work correctly, it seems that I need to create a mapper function and then manually hook it up with a field resolver.
I'd rather match your Tier example in Scalar and create a type with marshal/unmarshal so that the field automatically resolves. However, Go doesn't allow methods on types that are defined in other packages (e.g., you can't do func (o obj) funcName where obj is defined as obj = pkg.Obj). So you can't refer to the external enum. And Generator fails with an incompatible error if you try to use
enum enums.Enum
in the types and then point to the type in the gqlgen.yml . So I can't see how the clean approach of the example is usable in the real world.Am I missing something? Is this something that is fixable in the generator?
Beta Was this translation helpful? Give feedback.
All reactions