ArchitectureSubscribing fields to types
Subscribing fields to types
Gato GraphQL uses the Publish-subscribe pattern to have fields be "subscribed" to types, in which a FieldResolver
entity has fields add to some TypeResolver
entity.
In this example, class UserFieldResolver
adds fields username
, email
and url
to class UserTypeResolver
, which resolves type User
:
The User
type does not know in advance which fields it will satisfy, but these (username
, email
and url
) are instead injected to the type by the field resolver.
This way, the GraphQL schema becomes easily extensible: by simply adding a field resolver, any extension can add new fields to an existing type (such as field User.shippingAddress
), or override how a field is resolved (such as redefining User.url
to return the user's website instead).