'Union type result in graphql subscription

Is it possible to have a union result on a graphql subscription, specifically in AppSync?

I tried the following in AppSync but got an error "The subscription has an invalid output type"

type Mutation {
  test1Mutation(test1arg: Test1Input!): Test1,
  test2Mutation(test2arg: Test2Input!): Test2
}

union DataMutationResult = Test1 | Test2

type Subscription {
    dataMutation(id: ID!): DataMutationResult
      @aws_subscribe(mutations: ["test1Mutation", "test2Mutation"])
}


Solution 1:[1]

AppSync requires the mutation return types in one subscription to be all same. I ended up making a wrapper return type for all mutations and having a union in that wrapper.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sisir