gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Custom scalars in federated schema

Open DRodriguez88 opened this issue 1 year ago • 0 comments

What happened?

I defined custom scalars with custom serialization logic in Service1. The Gateway can't resolve Service2's types who use Service1's custom scalar using Service1's custom scalar logic

What did you expect?

I have many types defined in Service1 who's resolvers are successfully used for fields in Service2. For example, Service1 defines a User with name/email. Service2 defines a Book who has a field user: User! @external That works as expected. My gateway successfully resolves Book.User.Name/Email.

Service1 has (among others) a custom scalar Thing which includes logic to parse the string as json, error handling, etc. Service2's Book also has a field foo: Thing

If I don't define Thing in Service2, gqlgen will break for undefined type. If i define Thing in Service2, the gateway won't use Service1's logic for it.

I would love to avoid having to re-define the logic in both places. I know a shared lib is possible, but these services are different languages

Minimal graphql.schema and models to reproduce

  • Successful schema federation
  • Custom scalar in some service
  • A second service who wants to use the scalar

versions

  • gqlgen v0.17.34
  • go 1.19.2

DRodriguez88 avatar Jul 06 '23 16:07 DRodriguez88