0

Within AppSync I have 2 users, Adam and Eve, both using the same Car (identified by a VIN).

When Adam startsCar he is subscribed to updateFuel mutation. How can I have Eve subscribing to updateFuel the moment Adam does a startsCar call ?

I am having problems wrapping my head around permissions and user context. startsCar is running with Adam's Cognito credentials and to have Eve receiving the event AFAIK the second updateFuel should be subscribed using Eve's Cognito credentials.

Is the above scenario possible ? How can the solution be approached ?

I have thought about adding Adam to an admin group but still stuck on the idea of subscribing to updateFuel as Eve.

TTy
  • 1

1 Answers1

0

This should totally be possible, all you have to do is add a filter to the subscription on the VIN. It could look something like this for the mutation:

type Mutation {
    ...other stuff...
    startCar(...other stuff..., VIN: String!): SomeType
}

And this for the subscription:

type Subscription {
    ...other stuff...
    updateFuel(VIN: String!): SomeType
    @aws_subscribe(mutations: ["startCar"])
}

It'd also be extensible for any other hypothetical passengers in the car, meaning no matter who started the car, whoever subscribed to it with this pattern would get an update on car start.

If you wanted to lock down the ability to see subscription updates, your intuition on groups would be a smart way to go, through an auth directive on the subscription field in your schema.

Jeff Bailey
  • 5,655
  • 1
  • 22
  • 30