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

feat(api): .subscribe() for GraphQL #1915

Merged
merged 37 commits into from
Aug 26, 2022
Merged

feat(api): .subscribe() for GraphQL #1915

merged 37 commits into from
Aug 26, 2022

Conversation

ragingsquirrel3
Copy link
Contributor

@ragingsquirrel3 ragingsquirrel3 commented Jul 21, 2022

This PR has subscriptions for GraphQL in dart. It implements the appsync real-time client described on https://docs.aws.amazon.com/appsync/latest/devguide/aws-appsync-real-time-data.html.

It does not implement reconnect on error or backoff/retry.

It does not include increased integration tests for other auth modes.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2022

Codecov Report

Merging #1915 (6e384c3) into feat/api-next (3ac59f4) will increase coverage by 0.22%.
The diff coverage is 71.92%.

@@                Coverage Diff                @@
##           feat/api-next    #1915      +/-   ##
=================================================
+ Coverage          44.82%   45.05%   +0.22%     
=================================================
  Files                129      129              
  Lines               7752     7853     +101     
=================================================
+ Hits                3475     3538      +63     
- Misses              4277     4315      +38     
Flag Coverage Δ
android-unit-tests ∅ <ø> (∅)
flutter-unit-tests 30.00% <71.92%> (+1.50%) ⬆️
ios-unit-tests 89.48% <ø> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...kages/api/amplify_api/lib/src/api_plugin_impl.dart 81.73% <30.00%> (-5.51%) ⬇️
..._api/lib/src/graphql/ws/web_socket_connection.dart 59.77% <59.77%> (ø)
...plify_api/lib/src/graphql/ws/web_socket_types.dart 79.36% <79.36%> (ø)
...phql/ws/web_socket_message_stream_transformer.dart 90.47% <90.47%> (ø)
..._api/lib/src/decorators/web_socket_auth_utils.dart 100.00% <100.00%> (ø)
.../ios/unit_tests/amplify_flutter_exampleTests.swift
...plify_flutter/example/ios/Runner/AppDelegate.swift
...ter/example/ios/unit_tests/AtomicResultTests.swift
...e/ios/unit_tests/MockAnalyticsCategoryPlugin.swift

@ragingsquirrel3
Copy link
Contributor Author

ragingsquirrel3 commented Jul 27, 2022

I'm still working on this, especially testing, logging, error handling, many comments not addressed. However, I did refactor the auth logic to use more pure functions and added lots of comments there. Let me know if still difficult to follow.

Copy link
Contributor

@Equartey Equartey left a comment

Choose a reason for hiding this comment

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

Nice work!

Question: Does the example app need to be updated to reflect any api changes?

@ragingsquirrel3
Copy link
Contributor Author

Nice work!

Question: Does the example app need to be updated to reflect any api changes?

No API changes for subscriptions, though I did just make a change to example app with last rev so unsubscribe button works.

@ragingsquirrel3 ragingsquirrel3 marked this pull request as ready for review August 16, 2022 20:43
@ragingsquirrel3 ragingsquirrel3 requested a review from a team as a code owner August 16, 2022 20:43
@@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:async';
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I never noticed this - but why are the other method channel tests/infra hanging around still? Outside of the configure API, we have no use for them anymore. These tests should just replace the old subscribe tests.

Copy link
Contributor Author

@ragingsquirrel3 ragingsquirrel3 Aug 17, 2022

Choose a reason for hiding this comment

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

I would rather do the cleanup in a single, separate PR. There was a task we mentioned in grooming for it.

Copy link
Contributor

@Equartey Equartey left a comment

Choose a reason for hiding this comment

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

Good work on the revisions. I noticed some things that will be nice for reconnection :)

packages/api/amplify_api/test/dart_graphql_test.dart Outdated Show resolved Hide resolved

/// Extension of [WebSocketConnection] that stores messages internally instead
/// of sending them.
class MockWebSocketConnection extends WebSocketConnection {
Copy link
Contributor

Choose a reason for hiding this comment

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

At some point we should be mocking/injecting the WebSocketChannel instead and not overriding methods since it becomes unclear what's being tested. Like here, I guess we're testing everything but connect/send - but those seem like good things to test too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, I put a task in backlog to improve this

Copy link
Contributor

@dnys1 dnys1 left a comment

Choose a reason for hiding this comment

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

This looks good for now. Once the method channel stuff is gone, I would recommend enabling lints at that point and doing the clean up for that so that future PRs meet spec. I've withheld all my formatting/style comments because it's easier if the analyzer prompts you as you go.

}

/// Times out the connection (usually if a keep alive has not been received in time).
void _timeout(Duration timeoutDuration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this method do more, like close the WS connection? I guess Elijah's PR will address that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think there will be more cleanup here but will leave for Elijah.

@ragingsquirrel3 ragingsquirrel3 merged commit 4009458 into aws-amplify:feat/api-next Aug 26, 2022
@ragingsquirrel3 ragingsquirrel3 deleted the feat/api-next-subscription branch August 26, 2022 16:13
ragingsquirrel3 pushed a commit that referenced this pull request Sep 9, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
ragingsquirrel3 pushed a commit that referenced this pull request Sep 14, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
ragingsquirrel3 pushed a commit that referenced this pull request Sep 15, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
ragingsquirrel3 pushed a commit that referenced this pull request Sep 26, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
ragingsquirrel3 pushed a commit that referenced this pull request Oct 19, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
ragingsquirrel3 pushed a commit that referenced this pull request Nov 8, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
HuiSF pushed a commit to HuiSF/amplify-flutter that referenced this pull request Nov 10, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
ragingsquirrel3 pushed a commit that referenced this pull request Nov 10, 2022
Co-authored-by: Elijah Quartey <Equartey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants