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
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a68b67a
chore!(api): migrate API category type definitions (#1640)
Jun 15, 2022
6f4c84f
chore(api): API Native Bridge for .addPlugin() (#1756)
Equartey Jun 23, 2022
7b4e0ca
chore(api): API Pigeon update (#1813)
Equartey Jun 27, 2022
26b23b6
feat(api): REST methods in dart with auth mode none (#1783)
Jun 27, 2022
e3c9cf6
feat!(api): GraphQL API key auth mode (#1858)
Equartey Jul 13, 2022
18e4272
feat!(core,auth): auth providers definition and CognitoIamAuthProvide…
Jul 19, 2022
7a98c5a
feat(core,api): IAM auth mode for HTTP requests (REST and GQL) (#1893)
Jul 21, 2022
5f2783b
feat(api): .subscribe() for GraphQL
Jul 21, 2022
55931aa
change name
Jul 21, 2022
b6ebdab
add some unit tests
Jul 26, 2022
dcaeba1
refactor a little
Jul 26, 2022
5715cb5
some renames
Jul 27, 2022
db28cab
feat(api): GraphQL Custom Request Headers (#1938)
Equartey Jul 29, 2022
c8297a6
feat(auth,api): cognito user pools auth provider & auth mode for API …
Aug 8, 2022
a62dc21
Merge branch 'feat/api-next' into feat/api-next-subscription
Aug 9, 2022
c464e6e
change disconnect
Aug 10, 2022
d93e00c
add logger
Aug 10, 2022
ac5348a
throw error during connection
Aug 11, 2022
2bc9024
expand unit tests
Aug 15, 2022
bdf706f
chore!(api): migrate API category type definitions (#1640)
Jun 15, 2022
ef1b223
chore(api): API Native Bridge for .addPlugin() (#1756)
Equartey Jun 23, 2022
4621a66
chore(api): API Pigeon update (#1813)
Equartey Jun 27, 2022
438c236
feat(api): REST methods in dart with auth mode none (#1783)
Jun 27, 2022
c99ca0c
feat!(api): GraphQL API key auth mode (#1858)
Equartey Jul 13, 2022
98891d7
feat!(core,auth): auth providers definition and CognitoIamAuthProvide…
Jul 19, 2022
d0a254e
feat(core,api): IAM auth mode for HTTP requests (REST and GQL) (#1893)
Jul 21, 2022
c63ddd6
feat(api): GraphQL Custom Request Headers (#1938)
Equartey Jul 29, 2022
64a50f6
feat(auth,api): cognito user pools auth provider & auth mode for API …
Aug 8, 2022
02c51fe
Merge branch 'feat/api-next' into feat/api-next-subscription
Aug 16, 2022
8b125c6
correct error handling
Aug 18, 2022
7300024
fix(auth): correct auth providers imports from rebase (#2042)
Aug 22, 2022
8eebbe4
Merge branch 'feat/api-next' into feat/api-next-subscription
Aug 22, 2022
e1ac0ce
improve test syntax
Aug 22, 2022
b6358fc
change null safety
Aug 22, 2022
a7a9339
Merge branch 'feat/api-next' into feat/api-next-subscription
Aug 23, 2022
d09da9a
undo plist change
Aug 23, 2022
6e384c3
make enum messageType
Aug 23, 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
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
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 @@ -77,6 +77,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';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';

Expand Down
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';
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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ abstract class AmplifyPluginInterface {
Future<void> addPlugin() async {}

/// Configures the plugin using the registered [config].
Future<void> configure({AmplifyConfig? config}) async {}
Future<void> configure({
AmplifyConfig? config,
required AmplifyAuthProviderRepository authProviderRepo,
}) async {}

/// Resets the plugin by removing all traces of it from the device.
@visibleForTesting
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify_core/lib/src/types/api/api_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export 'graphql/graphql_response.dart';
export 'graphql/graphql_response_error.dart';
export 'graphql/graphql_subscription_operation.dart';

export 'rest/http_payload.dart';
export 'rest/rest_exception.dart';
export 'rest/rest_operation.dart';
export 'rest/rest_options.dart';
export 'rest/rest_response.dart';

export 'types/pagination/paginated_model_type.dart';
export 'types/pagination/paginated_result.dart';
Loading