-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Is this related to a new or existing framework?
React Native
Is this related to a new or existing API?
DataStore
Is this related to another service?
AppSync
Describe the feature you'd like to request
Was looking at Subscriptions by Argument used in Amplify API GraphQL
(https://docs.amplify.aws/guides/api-graphql/subscriptions-by-id/q/platform/js/).
Didn't find a way to do it using DataStore, and the underlying observeQuery API (https://docs.amplify.aws/lib/datastore/real-time/q/platform/js/#observe-query-results-in-real-time).
type Comment @model {
id: ID!
content: String
postCommentsId: ID!
}
type Subscription {
onCommentByPostId(postCommentsId: ID!): Comment
@aws_subscribe(mutations: ["createComment"])
}
import { API } from 'aws-amplify';
import { onCommentByPostId } from './graphql/subscriptions';
API.graphql({
query: onCommentByPostId,
variables: {
postCommentsId: "12345"
}
})
.subscribe({
next: data => {
console.log('data: ', data)
}
})
Describe the solution you'd like
I am hoping to see if developers are able to send argument (such as user_id) to the subscription so I can have fine grained auth control for GraphQL subscription as mentioned in the Amplify API GraphQL (Subscription by id guide above).
and with AppSync Lambda Authorizer, I can do the following request mapping for subscription:
## [Start] Subscription Request template. **
#if(${ctx.identity.resolverContext.uid} == ${context.args.uid})
$util.toJson({
"version": "2018-05-29",
"payload": {}
})
#else
$utils.unauthorized()
#end
## [End] Subscription Request template. **
Describe alternatives you've considered
I do consider predicates, but it does not apply to auth scenario at subscription
https://docs.amplify.aws/lib/datastore/data-access/q/platform/js/#predicates
I also consider using the Amplify GraphQL API (Subscription by id guide), but then I will need to build my own datastore, which cannot leverage the Amplify DataStore.
I think if Amplify GraphQL API can do this, DataStore feature request should have a chance :)
Additional context
No response
Is this something that you'd be interested in working on?
- 👋 I may be able to implement this feature request
-
⚠️ This feature might incur a breaking change