Skip to content

Commit

Permalink
chore(api): use library.yaml lint rules and reformat to match (#2171)
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Sheppard committed Nov 10, 2022
1 parent 76a70d7 commit f13858b
Show file tree
Hide file tree
Showing 35 changed files with 570 additions and 514 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class APICategory extends AmplifyCategory<APIPluginInterface> {
/// Sends a GraphQL query request and returns the response in a cancelable `GraphQLOperation`.
///
/// See https://docs.amplify.aws/lib/graphqlapi/query-data/q/platform/flutter/
/// and for more information.
/// for more information.
GraphQLOperation<T> query<T>({required GraphQLRequest<T> request}) =>
defaultPlugin.query(request: request);

Expand Down
5 changes: 1 addition & 4 deletions packages/api/amplify_api/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
include: package:amplify_lints/library_core.yaml
include: package:amplify_lints/library.yaml

analyzer:
exclude:
- '**/*.mocks.dart'
errors:
# TODO: Renable when logging library is finished
avoid_print: ignore
2 changes: 1 addition & 1 deletion packages/api/amplify_api/example/lib/models/Blog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: prefer_const_literals_to_create_immutables, prefer_single_quotes
// ignore_for_file: prefer_const_literals_to_create_immutables, prefer_single_quotes, inference_failure_on_untyped_parameter

/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand Down
2 changes: 1 addition & 1 deletion packages/api/amplify_api/example/lib/models/Comment.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: avoid_catches_without_on_clauses, prefer_const_literals_to_create_immutables, prefer_single_quotes
// ignore_for_file: avoid_catches_without_on_clauses, prefer_const_literals_to_create_immutables, prefer_single_quotes, inference_failure_on_untyped_parameter

/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand Down
3 changes: 1 addition & 2 deletions packages/api/amplify_api/example/lib/models/Post.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: avoid_catches_without_on_clauses, prefer_single_quotes, prefer_const_literals_to_create_immutables
// ignore_for_file: avoid_catches_without_on_clauses, prefer_single_quotes, prefer_const_literals_to_create_immutables, inference_failure_on_untyped_parameter

/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand Down Expand Up @@ -50,7 +50,6 @@ class Post extends Model {
String get title {
try {
return _title!;
// ignore: avoid_catches_without_on_clauses
} catch (e) {
throw new AmplifyCodeGenModelException(
AmplifyExceptionMessages
Expand Down
7 changes: 3 additions & 4 deletions packages/api/amplify_api/lib/amplify_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import 'package:amplify_api/src/api_plugin_impl.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:meta/meta.dart';

export 'package:amplify_api/src/graphql/model_mutations.dart';
export 'package:amplify_api/src/graphql/model_queries.dart';
export 'package:amplify_api/src/graphql/model_subscriptions.dart';
export 'package:amplify_core/src/types/api/api_types.dart';

export './model_mutations.dart';
export './model_queries.dart';
export './model_subscriptions.dart';

/// {@template amplify_api.amplify_api}
/// The AWS implementation of the Amplify API category.
/// {@endtemplate}
Expand Down
21 changes: 12 additions & 9 deletions packages/api/amplify_api/lib/src/api_plugin_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ library amplify_api;
import 'dart:io';

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_api/src/amplify_api_config.dart';
import 'package:amplify_api/src/amplify_authorization_rest_client.dart';
import 'package:amplify_api/src/graphql/app_sync_api_key_auth_provider.dart';
import 'package:amplify_api/src/graphql/oidc_function_api_auth_provider.dart';
import 'package:amplify_api/src/graphql/send_graphql_request.dart';
import 'package:amplify_api/src/graphql/ws/web_socket_connection.dart';
import 'package:amplify_api/src/native_api_plugin.dart';
import 'package:amplify_api/src/oidc_function_api_auth_provider.dart';
import 'package:amplify_api/src/util/amplify_api_config.dart';
import 'package:amplify_api/src/util/amplify_authorization_rest_client.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -65,9 +65,11 @@ class AmplifyAPIDart extends AmplifyAPI {
}) async {
final apiConfig = config?.api?.awsPlugin;
if (apiConfig == null) {
throw const ApiException('No AWS API config found',
recoverySuggestion: 'Add API from the Amplify CLI. See '
'https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/flutter/#configure-api');
throw const ApiException(
'No AWS API config found',
recoverySuggestion: 'Add API from the Amplify CLI. See '
'https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/flutter/#configure-api',
);
}
_apiConfig = apiConfig;
_authProviderRepo = authProviderRepo;
Expand Down Expand Up @@ -119,9 +121,10 @@ class AmplifyAPIDart extends AmplifyAPI {
} on PlatformException catch (e) {
if (e.code == 'AmplifyAlreadyConfiguredException') {
throw const AmplifyAlreadyConfiguredException(
AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
recoverySuggestion:
AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion);
AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
recoverySuggestion:
AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion,
);
}
throw AmplifyException.fromMap((e.details as Map).cast());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Future<AWSBaseHttpRequest> authorizeHttpRequest(
final apiKey = endpointConfig.apiKey;
if (apiKey == null) {
throw const ApiException(
'Auth mode is API Key, but no API Key was found in config.');
'Auth mode is API Key, but no API Key was found in config.',
);
}

final authorizedRequest = await authProvider.authorizeRequest(
Expand All @@ -55,9 +56,10 @@ Future<AWSBaseHttpRequest> authorizeHttpRequest(
return authorizedRequest;
case APIAuthorizationType.iam:
final authProvider = _validateAuthProvider(
authProviderRepo
.getAuthProvider(APIAuthorizationType.iam.authProviderToken),
authType);
authProviderRepo
.getAuthProvider(APIAuthorizationType.iam.authProviderToken),
authType,
);
final service = endpointConfig.endpointType == EndpointType.graphQL
? AWSService.appSync
: AWSService.apiGatewayManagementApi; // resolves to "execute-api"
Expand Down Expand Up @@ -85,10 +87,14 @@ Future<AWSBaseHttpRequest> authorizeHttpRequest(
}

T _validateAuthProvider<T extends AmplifyAuthProvider>(
T? authProvider, APIAuthorizationType authType) {
T? authProvider,
APIAuthorizationType authType,
) {
if (authProvider == null) {
throw ApiException('No auth provider found for auth mode ${authType.name}.',
recoverySuggestion: 'Ensure auth plugin correctly configured.');
throw ApiException(
'No auth provider found for auth mode ${authType.name}.',
recoverySuggestion: 'Ensure auth plugin correctly configured.',
);
}
return authProvider;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class AppSyncApiKeyAuthProvider extends ApiKeyAmplifyAuthProvider {
}) async {
if (options == null) {
throw const ApiException(
'Called API key auth provider without passing a valid API key.');
'Called API key auth provider without passing a valid API key.',
);
}
request.headers.putIfAbsent(xApiKey, () => options.apiKey);
return request;
Expand Down
Loading

0 comments on commit f13858b

Please sign in to comment.