aws-mobile-appsync-sdk-js
aws-mobile-appsync-sdk-js copied to clipboard
Subscriptions with union type result
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.
Any updates on this?
@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"])
}
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 👍
Thanks @sis-dk for the work around