Search code examples
amazon-web-servicesgraphqlapollo-serveraws-appsync

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

  • 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.