mhallin/graphql_ppx

Expose types for interface/union types

arnarthor opened this issue · 0 comments

I have query which looks something like this

        query FeedQuery {
          feed {
            title
            ... on Picture {
              url
              description
            }
            ... on Video {
               length
            }
          }
        }

Which has the return type

{. "feed": [ 
  | `Picture({. "title": string, "url": string, "description": string}) 
  | `Video({. "title": string, "length": int}) ]
}

Would it be possible to expose the type of the polymorphic variant here instead of inlining it.
My use case is that I have a subscription and a query fetching the same things, and I don't want to store these things as a Js.t({. "feed": ...}) but instead extract the actual variant types and store those as a list in my app.

I first fetch the feed from the query, and then use subscriptions to update the feed by injecting new objects. Having a list of the above mentioned Js.t is way more awkward than just storing a list of the actual variant.

I'm okay with converting between the subscription and query types since they won't be the same thing. But not having to extract it first from a Js.t would help a lot.