9

We are having huge troubles with subscriptions with arguments

to simplify the problem Here are the steps to reproduce

create a simpleSchema

type Mutation {
    testSubMutation(param: String!): String
}

type Query {
    testQuery: String
}

type Subscription {
    testSubs(param: String): String
        @aws_subscribe(mutations: ["testSubMutation"])
}

I attached a local resolver to the mutation which returns the timestamp.

in one window open the app sync query tab and make the subscription

subscription sub{
  testSubs
}

in the other window make a mutation

mutation mut{
  testSubMutation(param:"123")
}

works like a charm

now change the subscription to listen to a parameter

subscription sub{
  testSubs(param:"123")
}

Does not work any more. :(

Any help is appreciated.

Gaurav Lanjekar
  • 185
  • 1
  • 8

2 Answers2

18

Subscriptions require the parameter you're filtering on to be in the response of the mutation. Could you try updating your mutation to this?

mutation mut{
  testSubMutation(param:"123") {
    param
  }
}
Jeff Bailey
  • 5,655
  • 1
  • 22
  • 30
  • Is it written somewhere in the documentation? It does work perfectly, but just a bit weird, that response of a mutation depends on it's arguments – Rax Wunter Aug 02 '18 at 15:02
  • 1
    Can you subscribe to changes in the database that were made through the DynamoDB GUI and not a GraphQL mutation? – lurning too koad Feb 06 '19 at 23:44
  • 1
    @hgale I don't think so, just because AppSync and Dyanmo are two different systems. AppSync doesn't know or care if requests are being processed by a Dynamo endpoint or a Lambda or something else. You could hook up to the dynamo stream for the table to fire when the table is modified and use that to send a non-AppSync websocket message to a browser. But as far as AppSync is concerned, it just sees requests coming in and out without much intelligence about how they are being resolved underneath. – bsberry Mar 28 '19 at 14:16
  • Sorry for being slow, I missed your question, @hgale. Hober is correct. – Jeff Bailey Mar 29 '19 at 19:02
  • Wow... That is so silly. And as mentioned by @Rax Wunter I did not find this in the documentation. – Dean Koštomaj Oct 29 '19 at 17:27
1

I'm doing same as above for subscription but not getting response, It's only working with one argument room

mutation addMessage {
  addMessage(input: { 
  room: "45a87f5b-ef9e-41cd-9cd7-f3e2f4946d31", 
  receiver: "3cea9c02-1cf5-4248-8ebe-3580a7a47b8b" }) {
   id
   room
   receiver {
    id
    userName
   }
  }
 }

subscription roomMessage {
  roomMessage(room: "45a87f5b-ef9e-41cd-9cd7-f3e2f4946d31", 
  receiver: "3cea9c02-1cf5-4248-8ebe-3580a7a47b8b") {
    id
    room
    receiver {
      id
      userName
    }
  }
}