Hey everyone, seeking advice. the GraphQL spec spo...
# prisma-whats-new
c
Hey everyone, seeking advice. the GraphQL spec sports a Union type to help querying multiple types. It's in the feature pipeline here: https://github.com/graphcool/feature-requests/issues/165 In the meantime though, I'm looking to merge two different types into a single "stream" and sort that stream by
createdAt
. The main way I can think to do this is by using a through type that manually merges the two. Is there a better option, and if not, what are the performance implications of using that strategy?
n
@ckelley can you describe exactly what you're planning to do? How would the through type merge both streams?
c
So, I have two types:
Note
and
Interaction
. They contain different types of information about a
Person
. I want to display them in a "timeline" format, where they are merged in the UI into a single list sorted by the creation date of the objects. I'm thinking ahead about the issues of paginating + ordering the results. If
Note
and
Interaction
are connected directly to
Person
, I'd likely have to sort them by
createdAt
on the client side.
n
instead, you could have a forth type
TimelineItem
that has two one-to-one relations to both
Note
and
Interaction
but is only ever connected to one of them
a
Yes, create TimelineItems in a RP or SSS for both types, then query on TimeLineItem
n
I don't think a function has to be involved here?
c
@nilan that would make sense. theoretically, if Union types were implemented, would I be able to sort the merged types by a property (such as createdAt) that they both share?
a
Well, the function would only help if you don't want to do a nested mutation on
Note
and
Interaction
to create the
TimelineItem
.
c
@agartha Was thinking about the function method earlier. Could have SSS to automatically categorize Notes and Interactions as TimelineItems.
a
That was what I meant. Make the TimelineItem optional on the side or
Note
and
Interaction
, then take care of it in a SSS or RP hook.