Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS AppSync - Subscription to a mutation does not return the desired fields

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:

  • The mutation works i.e. the body can be updated in the table behind the scenes.
  • I did not attach a resolver to the subscription entry, but there is one for the mutation. It should be this way afaik.
like image 565
vahdet Avatar asked Dec 03 '22 10:12

vahdet


1 Answers

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
  }
}
like image 150
Rohan Deshpande Avatar answered Dec 25 '22 08:12

Rohan Deshpande