aws / aws/aws-appsync-community

Subscription filtering

Open
#229 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
507
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Hi, I've been struggling with a problem for a while now
My schema:
```
type Room @aws_cognito_user_pools {
id: ID!
name: String!
users(filter: ModelUserRoomFilterInput): ModelUserRoomConnection
userRooms(filter: ModelUserRoomFilterInput): ModelUserRoomConnection
}
type User @aws_cognito_user_pools {
id: ID!
username: String!
rooms(filter: ModelUserRoomFilterInput): ModelUserRoomConnection
}

type UserRoom @aws_cognito_user_pools {
id: ID!
roomID: ID!
room: Room!
userID: ID!
user: User!
}

type Mutation {
newRoom(input: NewRoomInput!): Room @aws_cognito_user_pools
}

input NewRoomInput {
name: String!
userIDs: [ID!]!
}

type Subscription {
onNewRoomByUser: Room @aws_subscribe(mutations: ["newRoom"]) @aws_cognito_user_pools
}
```

Pass the room name and userIDs to the mutation in an array as strings. The mutation is implemented as a Pipeline:
```
{
type: 'Mutation',
field: 'newRoom',
kind: 'PIPELINE',
functions: ['createRoom', 'createUserRoom']
},
```

function createRoom creates a room and createUserRoom creates a relationship in UserRooms with given id and my id taken from cognito. I want my subscription to notify me whenever an association with UserRoom is created, but I want it to be filtered by the id of a particular user. The problem here is that both mutation and subscription are associated with the Room type, which does not have the userID attribute. I tried in mapping templates to add something like $extensions.setSubscriptionFilter but it also did not help, probably I implement it wrong. (In subscription I don't give userID parameter because I take it later from cognito identity)
Does anyone know how I could solve this problem? How should the request and response of mapping templates for subscriptions look like?

Contributor guide

Open the contributing guide

Research direction

Start with the schema's newRoom mutation, onNewRoomByUser subscription, and the createRoom/createUserRoom pipeline functions. Read the AWS AppSync subscription mapping-template and filtering behavior first, then determine how the Cognito user ID and UserRoom association can reach the subscription filter. Done means the subscriber is notified only when an association for that user is created.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, graphql
Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.