Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for complete messages to be captured in a subscription #9898

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kddejong
Copy link

@kddejong kddejong commented May 11, 2022

Description of changes

AppSync now supports unsubscribing connections . Previously this message is not available to uses of the amplify-js libraries. This PR will allow a user to capture this completion message and take the appropriate action inside their application

Issue #, if available

Description of how you validated changes

const subscription = API.graphql<Observable<{
      provider: any;
      value: GraphQLResult<any>;
    }>>(graphqlOperation(onCreateMessage))
    .subscribe({
      next: ({ provider, value }: {provider: any, value: GraphQLResult}) => {
        console.log({ provider, value });
      },
      complete: () => console.log('Complete'),
      error: ({ provider, error }: {provider: any, error: GraphQLResult}) => {
        error.errors?.forEach(e => {
          console.log(e);
        });
      }
    });

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented May 11, 2022

Codecov Report

Merging #9898 (86b72d9) into main (9831d3d) will increase coverage by 5.12%.
The diff coverage is 91.69%.

@@            Coverage Diff             @@
##             main    #9898      +/-   ##
==========================================
+ Coverage   78.34%   83.47%   +5.12%     
==========================================
  Files         250      253       +3     
  Lines       18339    18201     -138     
  Branches     3955     3901      -54     
==========================================
+ Hits        14368    15193     +825     
+ Misses       3840     2918     -922     
+ Partials      131       90      -41     
Impacted Files Coverage Δ
packages/core/src/constants.ts 100.00% <ø> (ø)
packages/datastore/src/sync/index.ts 73.16% <ø> (+59.74%) ⬆️
packages/datastore/src/sync/merger.ts 91.30% <ø> (ø)
packages/datastore/src/sync/outbox.ts 95.61% <ø> (+3.50%) ⬆️
...ages/datastore/src/sync/processors/subscription.ts 39.23% <28.57%> (+3.27%) ⬆️
packages/api-graphql/src/GraphQLAPI.ts 87.50% <50.00%> (-0.42%) ⬇️
packages/api-rest/src/RestAPI.ts 95.34% <50.00%> (-0.72%) ⬇️
...ackages/datastore/src/sync/processors/errorMaps.ts 54.83% <54.83%> (ø)
packages/geo/src/Geo.ts 81.63% <65.78%> (-13.89%) ⬇️
packages/pushnotification/src/PushNotification.ts 49.07% <75.00%> (-0.24%) ⬇️
... and 65 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@siegerts siegerts added the first-time-contributor The contribution is the first for this user in the repo label May 12, 2022
@kddejong
Copy link
Author

Added tests and now have good codecov delta

Copy link
Member

@stocaaro stocaaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks like it will work as you propose. It also appears to add functionality that wouldn't impact the existing behavior. Have you linked it to a real project and exercised the behavior this change plugs into?

I think its technically an API change and it would be good to have verification that its working as expected in an end to end use case.

If you've done that validation and remove the comment, this change has my approval.

@@ -184,7 +184,7 @@ export class PubSubClass {
start: console.error,
next: value => observer.next({ provider, value }),
error: error => observer.error({ provider, error }),
// complete: observer.complete, // TODO: when all completed, complete the outer one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-contributor first-time-contributor The contribution is the first for this user in the repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amplify PubSub unsubscribe method does not report the status/complete before sign out?
4 participants