amplify-js icon indicating copy to clipboard operation
amplify-js copied to clipboard

Allow for complete messages to be captured in a subscription

Open kddejong opened this issue 3 years ago • 2 comments

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

  • [X] PR description included
  • [X] yarn test passes
  • [x] 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.

kddejong avatar May 11 '22 23:05 kddejong