aws / aws/aws-appsync-community
Allow Subscription to return a type that the Mutation Response Implements
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
```
interface SecretFooInterface {
secretFooFieldThatUsesServerFilteringForAccess: String
}
type SecretFoo implements SecretFooInterface {
secretFooFieldThatUsesServerFilteringForAccess: String
}
interface FooInterface {
publicFooField: String
}
type Foo implements FooInterface {
publicFooField: String
}
type Bar implements SecretFooInterface & FooInterface {
secretFooFieldThatUsesServerFilteringForAccess: String
publicFooField: String
barField: String
}
type Subscription {
# This would do a query for a list of friends, and do server side filtering to only allow certain people to subscribe
SubscribeSecretFoo: SecretFoo!
@aws_subscribe(mutations: ["CreateBar"])
SubscribePublicFoo: Foo
@aws_subscribe(mutations: ["CreateBar"])
}
type Mutation {
CreateBar: Bar!
}
```
Hi,
Essentially I have a use case where I want two subscriptions to the same mutation, where both subscriptions will subscribe to different field subsets of what the mutation returns, and to have a server side filter on on of the subscriptions to limit data access. As of right now, the subscription has to have the exact same return type as the mutation.
A bit more on the use case, I'm implementing voting where I want everyone to be able to subscribe to the vote increment/decrement, but in order to subscribe to the username they have to be in your list of friends ( protected using server side filtering). The non filtered subscription would never be able to put the username field in the request as per the the schema.
Currently I will have to use a dynamo stream to trigger a lambda that sends data to a different mutation, which would take up more resources quite a bit more resources than just subscribing to the same mutation.
**All I'd need to be able to implement this is to allow Subscriptions to return a type that implements the same interface as what the mutation return type implements**
I obviously have no idea about the internals of this, but my hope is that it would be low effort. And of course if theres another way to do this please let me know.
Contributor guide
Research direction
Start by reviewing the Subscription and Mutation schema types, the @aws_subscribe directive, and the interface implementations shown in the issue. The change is done when a subscription can return an interface-compatible type from the mutation while preserving distinct field subsets and server-side filtering.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, graphql
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100