question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Subscriptions with multiple optional parameters doesn't fire

See original GitHub issue

Describe the bug After implementing the custom subscription arguments here: https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js#filter-subscriptions-by-model-fields-andor-relations

The next time you run amplify push or amplify api gql-compile, your subscriptions will allow an id and/or commentTodoId argument on a Comment subscription. As long as your mutation on the Comment type returns the specified argument field from its query, AppSync filters which subscription events will be pushed to your subscribed client.

I have two subscriptions that I care about, one each for adding/removing from a collection. To use the example in the documentation, I have the equivalent of this:

type Subscription {
  onCreateComment(commentTodoId: String): Comment @aws_subscribe(mutations: "createComment")
  onDeleteComment(id: ID, commentTodoId: String): Comment @aws_subscribe(mutations: "deleteComment")
}

The create works as expected. The delete does not.

However, if I remove the id from the onDelete subscription and only have the second parameter, it works as expected, like so:

type Subscription {
  onCreateComment(commentTodoId: String): Comment @aws_subscribe(mutations: "createComment")
  onDeleteComment(commentTodoId: String): Comment @aws_subscribe(mutations: "deleteComment")
}

I’m not sure when this occurred, probably within the last one or two revisions of the CLI, but this appears to be a recent occurrence as this same part of my app has worked in the past without any recent changes on my part. The latest amplify update (either CLI or js library) has changed this behavior.

As a side note: I’m curious if this might be based on the id key specifically - I have another subscription based solely on an update that doesn’t seem to work any longer after the recent edition of the CLI or js. This would be the equivalent of:

  onUpdateComment(id: ID): Comment @aws_subscribe(mutations: "updateComment")

As in, whenever this comment updates, I want to listen to it. This does not appear to work. I would guess that if I took away ID and added some other qualifier, it would work. I will try this and report back.

To Reproduce Steps to reproduce the behavior:

  1. Have the following subscription:
type Subscription {
  onCreateComment(commentTodoId: String): Comment @aws_subscribe(mutations: "createComment")
  onDeleteComment(commentTodoId: String): Comment @aws_subscribe(mutations: "deleteComment")
}
  1. Implement and listen to the subscriptions. It works.
  2. Add the ID per the instructions at the link above:
type Subscription {
  onCreateComment(commentTodoId: String): Comment @aws_subscribe(mutations: "createComment")
  onDeleteComment(id:ID, commentTodoId: String): Comment @aws_subscribe(mutations: "deleteComment")
}
  1. onDelete no longer works.

Expected behavior Subscriptions work.

~ $ amplify -v 1.8.1

"aws-amplify": "^1.1.30",

P.S. - It would be nice for reproductions or testing if there was a codesandbox of some kind that was setup to implement most (if not all) of the CLI features, so that situations could be re-created more easily as a demo. We would be able to fork it and attempt to show reproductions of our issues…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
UnleashedMindcommented, Aug 16, 2019

Thanks @mwarger for the clarification I’ve reproduced the issue. this appears to be a server side bug, we will update you on its fix.

0reactions
github-actions[bot]commented, May 27, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple optional parameters in TypeScript - Stack Overflow
Optional parameters must be at the back and can only be left out if all later arguments are left out as well.
Read more >
Subscriptions - Apollo GraphQL Docs
A GraphQL subscription document parsed into an AST by graphql-tag . Optional for the useSubscription Hook since the subscription can be passed in...
Read more >
Named and Optional Arguments - C# Programming Guide
Named arguments in C# specify arguments by name, not position. ... In the example method below, the sellerName can't be null or white...
Read more >
Discounts for subscriptions | Stripe Documentation
Redeem coupons to apply discounts to the subscriptions you offer. You can also use coupons to create promotion codes to share with your...
Read more >
YouTube Embedded Players and Player Parameters
All of the following parameters are optional. Parameters. autoplay. This parameter specifies whether the initial video will automatically start to play when the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found