Search code examples
amazon-web-servicesaws-appsyncaws-appsync-ios

Appsync: Subscribe to element in array


With respect to AWS AppSync Is there a way of subscribing to an element in an array , eg:

onSendMessage(recipientIds:[myID,otherPotentiallyRandomAndUnknownIds]) {

}

I have tried simply adding the element I'm looking for, however it doesn't trigger a subscription if I'm missing the other elements (and in order too)


Solution

  • Unfortunately this is something that can't be done trivially. Also the as you noted the order matters because in GraphQL it should viewed as a List (which is ordered). So the subscription triggers expecting the order you provided on the schema. It also expects the exact arguments you provide in the list because a GraphQL Schema is essentially viewed as a contract by clients so if the contract dictates that the subscription is on a List with these elements in this order - then it will initiate the subscription based on that.

    Now what you could do is set up a dynamo stream (assuming DynamoDB as your data source) that feeds any changes on the table into a lambda from where you can make a mutation on AppSync (depending on if a change to was made to an element in the array) to trigger a subscription (set up simple mutation/subscriptions for this use case only). This is sort of a hack-y workaround, and there may be other novel solutions you can explore.