I try to subscribe to mutations in a DynamoDB table in AWS AppSync. The schema briefly looks like follows:
type Post {
id: ID!
userId: String!
title: String
body: String!
}
input UpdatePostInput {
id: ID!
title: String
body: String
}
type Mutation {
updatePost(input: UpdatePostInput!): Post
}
type Subscription {
onUpdatePost(id: ID!): Post
@aws_subscribe(mutations: ["updatePost"])
}
Given the ID of the post, when I want to get the changes in the body of that post I tried making use of that subscription above as:
subscription OnUpdatePost {
onUpdatePost(id: "some-id") {
id
body ## This line should make the trick, but it does not
}
}
The subscription is fired -which is fine. However, the result contains only the ID
and __typename
, NOT the body
:
{
"data": {
"onUpdatePost": {
"id": "some-id",
"__typename": "Post"
}
}
}
Having body
among the fields should be enough following the guide here.
Am I missing something with this subscription setup?
Note:
mutation
works i.e. the body can be updated in the table behind the scenes.Subscriptions in AWS AppSync are invoked as a response to a mutation. Subscriptions are triggered from mutations and the mutation selection set is sent to subscribers.
I suspect that you aren't returning body
in your updatePost
mutation selection set. Add that field and the subscription will contain body
e.g.
mutation {
updatePost(input: { id: "some-id" }) {
id
body
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With