* Which Category is your question related to? *
GraphQL Transformer, VTL
* What AWS Services are you utilizing? *
AppSync
* Provide additional details e.g. code snippets *
Is there a way to create a subscription that accepts specific arguments in the annotated schema? Such as a subscription for comments on a particular Blog post:
type Subscription {
onCreateComment(postId: ID!) @aws_subscribe(mutations: ["createComment"])
}
And if not yet supported, is there a way to add it as a "pass-thru" so it ends up in the final schema? Currently adding it and running Amplify push deletes it from the annotated schema, not sure if that is by design or is a defect.
You can turn off the auto-generated subscriptions by passing subscriptions: null to @model. For example:
type Post @model(subscriptions: null) {
id: ID!
title: String!
}
You can then write your own subscription fields and paramerize them however you like:
type Subscription {
onCreateMessage(messageRoomId: ID!): Message @aws_subscribe(mutations: ["createMessage"])
}
In the future, the goal would be to generated correctly parameterized subscriptions automatically based on your @auth and @connection directives in the model.
Closing this issue. Feel free to re-open if you've any questions related to this issue.
In the future, the goal would be to generated correctly parameterized subscriptions automatically based on your @auth and @connection directives in the model.
@mikeparisstuff When can we expect that? I am trying to write a custom subscription using the owner as input, but I think it doesn't work because the owner is not explicitly defined in the table's schema.
I need some help here.
The APIService generated by codegen has generated this function.
SubscribeToNewMessageListener: Observable<SubscribeToNewMessageSubscription> = API.graphql(
graphqlOperation(
`subscription SubscribeToNewMessage($conversationId: ID!) {
subscribeToNewMessage(conversationId: $conversationId) {
__typename
author {
__typename
cognitoId
id
username
registered
}
content
conversationId
createdAt
id
isSent
recipient {
__typename
cognitoId
id
username
registered
}
sender
}
}`
)
) as Observable<SubscribeToNewMessageSubscription>;
I'm trying to call this listener from an angular page but I can not pass the parameter to the function
always get "Variable 'conversationId' has coerced Null value for NonNull type 'ID!'".
I have tried in all ways but I can not send it.
This is more or less my code.
constructor(
private api: APIService
) {}
ngOnInit() {
this.api.SubscribeToNewMessageListener
.map(msg => msg.conversationId = 'randomGUID')
.subscribe({
next: (x) => {console.log('Next',x)},
error: (e) => {console.log('Error', e)},
complete: () => {}
})
}
Another subscription without parameters, however, it works for me simply by subscribing to it.
Please need help.
Thanks you.
Hey @RidClick,
I'm stuck at this point too, did you manage to get rid of this problem? Have you found a solution?
Thanks in advance.
Edit: Found that you answered in https://github.com/aws-amplify/amplify-cli/issues/1021
@mikeparisstuff -- pleeeeeeeeeeeeez add parametrized subscriptions. It's such a big hole in the framework. Actually it renders it unusable for most real-time apps.
https://github.com/aws-amplify/amplify-cli/issues/1021
https://github.com/aws-amplify/amplify-cli/issues/1766
Im also a bit lost here. So codegen creates code which is not working when you need an argument as owner for a subscription or? Or how can I pass the owner as input to the subscription in Angular with the generated code?
amplify --version --> 3.0.0
Most helpful comment
Im also a bit lost here. So codegen creates code which is not working when you need an argument as owner for a subscription or? Or how can I pass the owner as input to the subscription in Angular with the generated code?
amplify --version --> 3.0.0