aws-mobile-appsync-sdk-js icon indicating copy to clipboard operation
aws-mobile-appsync-sdk-js copied to clipboard

Subscriptions with union type result

Open sis-dk opened this issue 5 years ago • 4 comments

Do you want to request a feature or report a bug?

Request a feature

What is the current behavior?

The response type has to be same as that of the subscribed mutation. Which also means that all the mutations in the array for subscription must have same return type.

What is the expected behavior?

Allow union type result on subscriptions which would allow mutations with different return types to be used in the same subscription

Example:

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"])
}

This would be extremely helpful as I have a bunch of subscriptions and whenever my app is starts, it subscribes to all those subscriptions.

sis-dk avatar Feb 07 '19 06:02 sis-dk

Any updates on this?

adrianmakowiak avatar Jul 27 '20 18:07 adrianmakowiak

@adrianmakowiak I don't think its supported yet. I did this instead

union MutationData = Test1Result | Test2Result

type MutationResponse {
    data: MutationData
}

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

type Subscription {
    onTestMutation(tId: ID!): MutationResponse
        @aws_subscribe(mutations: ["test1Mutation", "test2Mutation"])
}

sis-dk avatar Aug 03 '20 13:08 sis-dk

Would be super convenient to have subscriptions allow union and interface types as return values. This would make merging multiple events into one really elegant. This efficiency also trickles down to the frontend where you don't have to subscribe to and maintain multiple subscriptions. @sis-dk thanks for the work around. Really nice example 👍

alextriaca avatar May 07 '21 13:05 alextriaca

Thanks @sis-dk for the work around

veerendrapatel avatar Mar 22 '23 11:03 veerendrapatel