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): Subscription Reconnection #2074

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
110672a
chore!(api): migrate API category type definitions (#1640)
Jun 15, 2022
66d99bf
chore(api): API Native Bridge for .addPlugin() (#1756)
Equartey Jun 23, 2022
2ff8e51
chore(api): API Pigeon update (#1813)
Equartey Jun 27, 2022
f4211af
feat(api): REST methods in dart with auth mode none (#1783)
Jun 27, 2022
5608b59
feat!(api): GraphQL API key auth mode (#1858)
Equartey Jul 13, 2022
985b045
feat!(core,auth): auth providers definition and CognitoIamAuthProvide…
Jul 19, 2022
7b6ce8e
feat(core,api): IAM auth mode for HTTP requests (REST and GQL) (#1893)
Jul 21, 2022
cb6fbdb
feat(api): GraphQL Custom Request Headers (#1938)
Equartey Jul 29, 2022
a1e8d9d
feat(auth,api): cognito user pools auth provider & auth mode for API …
Aug 8, 2022
3ac59f4
fix(auth): correct auth providers imports from rebase (#2042)
Aug 22, 2022
4009458
feat(api): .subscribe() for GraphQL (#1915)
Aug 26, 2022
48c9582
chore(api): Api Example - generate files for multi-plaform (#2080)
Equartey Sep 1, 2022
bef7f19
feat(api): Subscription Reconnection
Equartey Aug 30, 2022
fcc53a0
fix: unexposed retryTimeout
Equartey Aug 31, 2022
32178ca
fix: more robust uri replacement
Equartey Aug 31, 2022
8bc47dd
fix: syntax errors
Equartey Aug 31, 2022
826d470
fix: code review feedback 1
Equartey Sep 1, 2022
b786902
fix: export retry package
Equartey Sep 1, 2022
2abff51
fix: Hub Event errors
Equartey Sep 8, 2022
80aa0d5
fix: typos & PR comments
Equartey Sep 8, 2022
7fc1cea
fix: review comments
Equartey Sep 8, 2022
ff85ce2
fix: hub events types
Equartey Sep 9, 2022
9ddea6b
chore!(api): migrate API category type definitions (#1640)
Jun 15, 2022
8e52487
chore(api): API Native Bridge for .addPlugin() (#1756)
Equartey Jun 23, 2022
4941901
chore(api): API Pigeon update (#1813)
Equartey Jun 27, 2022
e780b22
feat(api): REST methods in dart with auth mode none (#1783)
Jun 27, 2022
daaff32
feat!(api): GraphQL API key auth mode (#1858)
Equartey Jul 13, 2022
d2bafc9
feat!(core,auth): auth providers definition and CognitoIamAuthProvide…
Jul 19, 2022
d6f6405
feat(core,api): IAM auth mode for HTTP requests (REST and GQL) (#1893)
Jul 21, 2022
d6d6019
feat(api): GraphQL Custom Request Headers (#1938)
Equartey Jul 29, 2022
5829de8
feat(auth,api): cognito user pools auth provider & auth mode for API …
Aug 8, 2022
f6c1c1b
fix(auth): correct auth providers imports from rebase (#2042)
Aug 22, 2022
2e05c6f
feat(api): .subscribe() for GraphQL (#1915)
Aug 26, 2022
3cae1e9
fix: unit & integ tests passing
Equartey Sep 9, 2022
e411b69
Merge branch 'feat/api-next' into feat/graphql-sub-reconnect
Equartey Sep 9, 2022
ea0950e
fix: removed dup var
Equartey Sep 9, 2022
76d9907
chore(api): Api Example - generate files for multi-plaform (#2080)
Equartey Sep 1, 2022
50f878e
Merge branch 'feat/api-next' into feat/graphql-sub-reconnect
Equartey Sep 9, 2022
e721775
Merge branch 'next' into feat/api-next
Equartey Sep 13, 2022
85c4227
Merge branch 'feat/api-next' into feat/graphql-sub-reconnect
Equartey Sep 13, 2022
e6230c5
chore(api): Refactor http client & cancelable operation (#2119)
Equartey Sep 14, 2022
12de4f0
Merge branch 'feat/api-next' into feat/graphql-sub-reconnect
Equartey Sep 14, 2022
5431552
fix: unit tests sans-reconnect & hub events
Equartey Sep 14, 2022
c926e66
Merge branch 'feat/api-next' into feat/graphql-sub-reconnect
Equartey Sep 27, 2022
426e0fa
Nothing gets past Travis 💪
Equartey Sep 27, 2022
51e8917
Integration file clean up
Equartey Sep 27, 2022
4aab1e1
missed two files
Equartey Sep 27, 2022
b8677e9
Removed http dep
Equartey Sep 27, 2022
3264fc7
Types, Lints, overrides, and Passing Tests.
Equartey Sep 28, 2022
d3896e7
Fixed pingClient init value
Equartey Sep 28, 2022
6b5bf50
fix: some nits
Equartey Sep 29, 2022
dc00c44
fix: some nits
Equartey Sep 30, 2022
b1f162b
fix: ios network none issue on second sub
Equartey Sep 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation

import connectivity_plus_macos
Copy link
Contributor

Choose a reason for hiding this comment

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

when I run aft bs I get similar file modifications in packages/api/amplify_api/example/macos/Flutter/GeneratedPluginRegistrant.swift. Should that be added as well?

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 noticed some extra generated files didn't committed. Will include them next push 👍


func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include "generated_plugin_registrant.h"

#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 3 additions & 1 deletion packages/amplify/amplify_flutter/lib/src/hybrid_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class AmplifyHybridImpl extends AmplifyClassImpl {
);
await Future.wait(
[
...API.plugins,
...Auth.plugins,
].map((p) => p.configure(config: amplifyConfig)),
].map((p) => p.configure(
config: amplifyConfig, authProviderRepo: authProviderRepo)),
eagerError: true,
);
await _methodChannelAmplify.configurePlatform(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation

import connectivity_plus_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include "generated_plugin_registrant.h"

#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
3 changes: 3 additions & 0 deletions packages/amplify_core/lib/amplify_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export 'src/types/api/api_types.dart';
/// Auth
export 'src/types/auth/auth_types.dart';

/// Auth providers
export 'src/types/common/amplify_auth_provider.dart';

/// Datastore
export 'src/types/datastore/datastore_types.dart' hide DateTimeParse;

Expand Down
8 changes: 7 additions & 1 deletion packages/amplify_core/lib/src/amplify_class_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import 'package:meta/meta.dart';
/// {@endtemplate}
@internal
class AmplifyClassImpl extends AmplifyClass {
/// Share AmplifyAuthProviders with plugins.
@protected
final AmplifyAuthProviderRepository authProviderRepo =
AmplifyAuthProviderRepository();

/// {@macro amplify_flutter.amplify_class_impl}
AmplifyClassImpl() : super.protected();

Expand Down Expand Up @@ -57,7 +62,8 @@ class AmplifyClassImpl extends AmplifyClass {
...Auth.plugins,
...DataStore.plugins,
...Storage.plugins,
].map((p) => p.configure(config: amplifyConfig)),
].map((p) => p.configure(
config: amplifyConfig, authProviderRepo: authProviderRepo)),
eagerError: true,
);
}
Expand Down
134 changes: 83 additions & 51 deletions packages/amplify_core/lib/src/category/amplify_api_category.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -21,17 +21,13 @@ class APICategory extends AmplifyCategory<APIPluginInterface> {
Category get category => Category.api;

// ====== GraphQL =======
GraphQLOperation<T> query<T>({required GraphQLRequest<T> request}) {
return plugins.length == 1
? plugins[0].query(request: request)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<GraphQLResponse<T>> query<T>(
{required GraphQLRequest<T> request}) =>
defaultPlugin.query(request: request);

GraphQLOperation<T> mutate<T>({required GraphQLRequest<T> request}) {
return plugins.length == 1
? plugins[0].mutate(request: request)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<GraphQLResponse<T>> mutate<T>(
{required GraphQLRequest<T> request}) =>
defaultPlugin.mutate(request: request);

/// Subscribes to the given [request] and returns the stream of response events.
/// An optional [onEstablished] callback can be used to be alerted when the
Expand All @@ -42,52 +38,88 @@ class APICategory extends AmplifyCategory<APIPluginInterface> {
Stream<GraphQLResponse<T>> subscribe<T>(
GraphQLRequest<T> request, {
void Function()? onEstablished,
}) {
return plugins.length == 1
? plugins[0].subscribe(request, onEstablished: onEstablished)
: throw _pluginNotAddedException('Api');
}
}) =>
defaultPlugin.subscribe(request, onEstablished: onEstablished);

// ====== RestAPI ======
void cancelRequest(String cancelToken) {
return plugins.length == 1
? plugins[0].cancelRequest(cancelToken)
: throw _pluginNotAddedException('Api');
}

RestOperation get({required RestOptions restOptions}) {
return plugins.length == 1
? plugins[0].get(restOptions: restOptions)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<AWSStreamedHttpResponse> delete(
String path, {
Map<String, String>? headers,
HttpPayload? body,
Map<String, String>? queryParameters,
String? apiName,
}) =>
defaultPlugin.delete(
path,
headers: headers,
body: body,
apiName: apiName,
);

RestOperation put({required RestOptions restOptions}) {
return plugins.length == 1
? plugins[0].put(restOptions: restOptions)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<AWSStreamedHttpResponse> get(
String path, {
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) =>
defaultPlugin.get(
path,
headers: headers,
apiName: apiName,
);

RestOperation post({required RestOptions restOptions}) {
return plugins.length == 1
? plugins[0].post(restOptions: restOptions)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<AWSStreamedHttpResponse> head(
String path, {
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) =>
defaultPlugin.head(
path,
headers: headers,
apiName: apiName,
);

RestOperation delete({required RestOptions restOptions}) {
return plugins.length == 1
? plugins[0].delete(restOptions: restOptions)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<AWSStreamedHttpResponse> patch(
String path, {
Map<String, String>? headers,
HttpPayload? body,
Map<String, String>? queryParameters,
String? apiName,
}) =>
defaultPlugin.patch(
path,
headers: headers,
body: body,
apiName: apiName,
);

RestOperation head({required RestOptions restOptions}) {
return plugins.length == 1
? plugins[0].head(restOptions: restOptions)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<AWSStreamedHttpResponse> post(
String path, {
Map<String, String>? headers,
HttpPayload? body,
Map<String, String>? queryParameters,
String? apiName,
}) =>
defaultPlugin.post(
path,
headers: headers,
body: body,
apiName: apiName,
);

RestOperation patch({required RestOptions restOptions}) {
return plugins.length == 1
? plugins[0].patch(restOptions: restOptions)
: throw _pluginNotAddedException('Api');
}
CancelableOperation<AWSStreamedHttpResponse> put(
String path, {
Map<String, String>? headers,
HttpPayload? body,
Map<String, String>? queryParameters,
String? apiName,
}) =>
defaultPlugin.put(
path,
headers: headers,
body: body,
apiName: apiName,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ library amplify_interface;
import 'dart:async';

import 'package:amplify_core/amplify_core.dart';
import 'package:async/async.dart';
Equartey marked this conversation as resolved.
Show resolved Hide resolved
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';

Expand Down
5 changes: 4 additions & 1 deletion packages/amplify_core/lib/src/hub/hub_channel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,4 +28,7 @@ enum HubChannel<HubEventPayload, E extends HubEvent<HubEventPayload>> {

/// Events of the DataStore category.
DataStore<DataStoreHubEventPayload, DataStoreHubEvent>(),

/// Events of the API category
Api<ApiHubEventPayload, ApiHubEvent>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,7 @@
*/

import 'package:amplify_core/amplify_core.dart';
import 'package:async/async.dart';
Equartey marked this conversation as resolved.
Show resolved Hide resolved
Equartey marked this conversation as resolved.
Show resolved Hide resolved
import 'package:meta/meta.dart';

abstract class APIPluginInterface extends AmplifyPluginInterface {
Expand All @@ -25,11 +26,13 @@ abstract class APIPluginInterface extends AmplifyPluginInterface {
ModelProviderInterface? get modelProvider => throw UnimplementedError();

// ====== GraphQL =======
GraphQLOperation<T> query<T>({required GraphQLRequest<T> request}) {
CancelableOperation<GraphQLResponse<T>> query<T>(
{required GraphQLRequest<T> request}) {
throw UnimplementedError('query() has not been implemented.');
}

GraphQLOperation<T> mutate<T>({required GraphQLRequest<T> request}) {
CancelableOperation<GraphQLResponse<T>> mutate<T>(
{required GraphQLRequest<T> request}) {
throw UnimplementedError('mutate() has not been implemented.');
}

Expand All @@ -50,31 +53,64 @@ abstract class APIPluginInterface extends AmplifyPluginInterface {
void registerAuthProvider(APIAuthProvider authProvider);

// ====== RestAPI ======
void cancelRequest(String cancelToken) {
throw UnimplementedError('cancelRequest has not been implemented.');
}

RestOperation get({required RestOptions restOptions}) {
throw UnimplementedError('get has not been implemented.');
CancelableOperation<AWSStreamedHttpResponse> delete(
String path, {
HttpPayload? body,
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) {
throw UnimplementedError('delete() has not been implemented');
}

RestOperation put({required RestOptions restOptions}) {
throw UnimplementedError('put has not been implemented.');
/// Uses Amplify configuration to authorize request to [path] and returns
/// [CancelableOperation] which resolves to standard HTTP
/// [Response](https://pub.dev/documentation/http/latest/http/Response-class.html).
CancelableOperation<AWSStreamedHttpResponse> get(
String path, {
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) {
throw UnimplementedError('get() has not been implemented');
}

RestOperation post({required RestOptions restOptions}) {
throw UnimplementedError('post has not been implemented.');
CancelableOperation<AWSStreamedHttpResponse> head(
String path, {
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) {
throw UnimplementedError('head() has not been implemented');
}

RestOperation delete({required RestOptions restOptions}) {
throw UnimplementedError('delete has not been implemented.');
CancelableOperation<AWSStreamedHttpResponse> patch(
String path, {
HttpPayload? body,
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) {
throw UnimplementedError('patch() has not been implemented');
}

RestOperation head({required RestOptions restOptions}) {
throw UnimplementedError('head has not been implemented.');
CancelableOperation<AWSStreamedHttpResponse> post(
String path, {
HttpPayload? body,
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) {
throw UnimplementedError('post() has not been implemented');
}

RestOperation patch({required RestOptions restOptions}) {
throw UnimplementedError('patch has not been implemented.');
CancelableOperation<AWSStreamedHttpResponse> put(
String path, {
HttpPayload? body,
Map<String, String>? headers,
Map<String, String>? queryParameters,
String? apiName,
}) {
throw UnimplementedError('put() has not been implemented');
}
}
Loading