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

chore(api,core): change API types #2148

Merged
merged 6 commits into from Sep 23, 2022
Merged

chore(api,core): change API types #2148

merged 6 commits into from Sep 23, 2022

Conversation

ragingsquirrel3
Copy link
Contributor

@ragingsquirrel3 ragingsquirrel3 commented Sep 21, 2022

This PR makes some changes to API category user-facing API (hate saying that) now that API review is finished. In summary:

  • brings back GraphQLOperation for query/mutate but based on CancelableOperation
  • brings back RestOperation with a factory to create from AWSHttpOperation and ensure .response not streamed type
  • brings back RestException and throws in REST methods when response not successful.
  • pass custom headers to GraphQL subscription registration methods
  • some formatting changes in the files I touched here

Also changes tests and makes a little change to AWSHttpClient to properly handle exceptions during transformResponse.

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

@@ -131,8 +131,12 @@ abstract class AWSBaseHttpClient extends AWSCustomHttpClient {
responseProgressCompleter.setSourceStream(operation.responseProgress);
operation.operation.then(
(resp) async {
resp = await transformResponse(resp);
completer.complete(resp);
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dnys1 double-checking this change makes sense? Without this, exceptions thrown in transformResponse weren't getting caught as expecting when await operation .response.

@ragingsquirrel3 ragingsquirrel3 marked this pull request as ready for review September 22, 2022 18:25
@ragingsquirrel3 ragingsquirrel3 requested a review from a team as a code owner September 22, 2022 18:25
@ragingsquirrel3 ragingsquirrel3 changed the title chore(api): change API types chore(api,core): change API types Sep 22, 2022
try {
resp = await transformResponse(resp);
completer.complete(resp);
} on Exception catch (e, st) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's fine, but let's add some tests since I didn't understand that about CancelableOperation.then

Also, let's handle all errors and exceptions this way so that errors don't get lost either.

Suggested change
} on Exception catch (e, st) {
} on Object catch (e, st) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change, plus added some unit tests in aws_common to test this behavior in request/response transform (though the REST tests in API category would fail as well without this change).

) async {
// For REST endpoints, throw [RestException] on non-successful responses.
if (endpointConfig.endpointType == EndpointType.rest &&
(response.statusCode < 200 || response.statusCode >= 300)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we throwing for 3xx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. 1) to be consistent w current behavior 2) though I guess you could make the case for following redirects that's not a change to behavior that was in API review.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Did not know that was the current behavior.

@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2022

Codecov Report

Merging #2148 (c946dda) into feat/api-next (fdf32f5) will increase coverage by 0.12%.
The diff coverage is 85.71%.

@@                Coverage Diff                @@
##           feat/api-next    #2148      +/-   ##
=================================================
+ Coverage          38.97%   39.10%   +0.12%     
=================================================
  Files                118      119       +1     
  Lines               6879     6900      +21     
=================================================
+ Hits                2681     2698      +17     
- Misses              4198     4202       +4     
Flag Coverage Δ
android-unit-tests ∅ <ø> (∅)
flutter-unit-tests 26.91% <85.71%> (+0.21%) ⬆️
ios-unit-tests 94.90% <ø> (-0.24%) ⬇️

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

Impacted Files Coverage Δ
...lify_api/lib/src/graphql/send_graphql_request.dart 75.00% <63.63%> (+1.66%) ⬆️
...api/lib/src/amplify_authorization_rest_client.dart 85.71% <77.77%> (ø)
...kages/api/amplify_api/lib/src/api_plugin_impl.dart 78.76% <95.45%> (+1.19%) ⬆️
..._api/lib/src/decorators/web_socket_auth_utils.dart 100.00% <100.00%> (ø)
...plify_api_ios/example/ios/Runner/AppDelegate.swift 0.00% <0.00%> (ø)

@ragingsquirrel3 ragingsquirrel3 merged commit baddbb9 into aws-amplify:feat/api-next Sep 23, 2022
ragingsquirrel3 pushed a commit that referenced this pull request Sep 26, 2022
ragingsquirrel3 pushed a commit that referenced this pull request Oct 19, 2022
ragingsquirrel3 pushed a commit that referenced this pull request Nov 8, 2022
HuiSF pushed a commit to HuiSF/amplify-flutter that referenced this pull request Nov 10, 2022
ragingsquirrel3 pushed a commit that referenced this pull request Nov 10, 2022
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.

None yet

4 participants