Hello!
I have several Queries and Mutations which logically share the same object (struct). For example the getUser(id)
method returns the same User
as the listUsers
(which returns an array of users in this example) and the login
(which returns the logged in user’s details).
In the iOS app I want to have variables with a common User
type to handle these results. Apollo’s code generation creates different models for each query, like GetUserQuery.Data.User
, UsersQuery.Data.User
and LoginMutation.Data.User
. Do these structs have a common ancestor, protocol or anything I can use for my internal data structure? Obviously I will need users of the same data kind to be able to extend it with helper functions (for example a hasValidName()
), to compare them and use them in general.
For this purpose my best solution was to introduce my own User
struct, which had helper methods for every request type which converted an Apollo struct to a User
type I created. Obviously this kills the simplicity of Apollo GraphQL instantly. Each model change caused me tens of source code lines and hours of work.
I am looking for a better way to do this. Maybe I overlooked something or missed an important note in the documentation? Please help me find the right way to solve this very common situation.