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: Lint fixes #1471

Merged
merged 13 commits into from
Apr 29, 2022
2 changes: 1 addition & 1 deletion packages/amplify/amplify_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
Expand Down
2 changes: 2 additions & 0 deletions packages/amplify/amplify_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dev_dependencies:
path: ../../../auth/amplify_auth_cognito
amplify_datastore:
path: ../../../amplify_datastore
amplify_datastore_plugin_interface:
path: ../../../amplify_datastore_plugin_interface
amplify_lints: ^1.0.0
amplify_storage_s3:
path: ../../../storage/amplify_storage_s3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AmplifyPluginRegistry {
}

/// The global, shared plugin registry.
static late final shared = AmplifyPluginRegistry._();
static final shared = AmplifyPluginRegistry._();

final Map<String, AmplifyPluginConfigFactory> _plugins = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,16 @@ class MethodChannelAmplify extends AmplifyClass {
await API.addPlugin(plugin);
} else {
throw AmplifyException(
'The type of plugin ' +
plugin.runtimeType.toString() +
' is not yet supported in Amplify.',
recoverySuggestion:
AmplifyExceptionMessages.missingRecoverySuggestion);
'The type of plugin ${plugin.runtimeType} is not yet supported '
'in Amplify.',
recoverySuggestion:
AmplifyExceptionMessages.missingRecoverySuggestion,
);
}
} on Exception catch (e) {
safePrint('Amplify plugin was not added');
throw AmplifyException(
'Amplify plugin ' +
plugin.runtimeType.toString() +
' was not added successfully.',
'Amplify plugin ${plugin.runtimeType} was not added successfully.',
recoverySuggestion: AmplifyExceptionMessages.missingRecoverySuggestion,
underlyingException: e.toString(),
);
Expand All @@ -96,9 +94,10 @@ class MethodChannelAmplify extends AmplifyClass {
// Validation #1
if (_isConfigured) {
throw const AmplifyAlreadyConfiguredException(
'Amplify has already been configured and re-configuration is not supported.',
recoverySuggestion:
'Check if Amplify is already configured using Amplify.isConfigured.',
'Amplify has already been configured and re-configuration is '
'not supported.',
recoverySuggestion: 'Check if Amplify is already configured using '
'Amplify.isConfigured.',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ class GraphQLRequestFactory {
// upperOutput and lowerOutput already '', done
break;
default:
throw ApiException('GraphQL Request Operation is currently unsupported',
recoverySuggestion: 'please use a supported GraphQL operation');
throw const ApiException(
'GraphQL Request Operation is currently unsupported',
recoverySuggestion: 'please use a supported GraphQL operation',
);
}

return DocumentInputs(upperOutput, lowerOutput);
Expand Down Expand Up @@ -237,8 +239,9 @@ class GraphQLRequestFactory {
}
// Public not() API only allows 1 condition but QueryPredicateGroup
// technically allows multiple conditions so explicitly disallow multiple.
throw ApiException(
'Unable to translate not() with multiple conditions.');
throw const ApiException(
'Unable to translate not() with multiple conditions.',
);
}

// and, or
Expand Down
22 changes: 13 additions & 9 deletions packages/amplify_api/lib/src/graphql/graphql_response_decoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ class GraphQLResponseDecoder {
return GraphQLResponse(
data: data as T, errors: errors); // <T> is implied
} else {
throw ApiException(
'Decoding of the response type provided is currently unsupported',
recoverySuggestion: "Please provide a Model Type or type 'String'");
throw const ApiException(
'Decoding of the response type provided is currently unsupported',
recoverySuggestion: "Please provide a Model Type or type 'String'",
);
}
}
// From here, it appears this is a response that must be parsed into a non-string object.

if (request.decodePath == null) {
throw ApiException('No decodePath found',
recoverySuggestion: 'Include decodePath when creating a request');
throw const ApiException(
'No decodePath found',
recoverySuggestion: 'Include decodePath when creating a request',
);
}

// Even if the data string is not null, it may be a null value shallow
Expand All @@ -67,10 +70,11 @@ class GraphQLResponseDecoder {
}
request.decodePath!.split('.').forEach((element) {
if (!dataJson!.containsKey(element)) {
throw ApiException(
'decodePath did not match the structure of the JSON response',
recoverySuggestion:
'Include decodePath when creating a request that includes a modelType.');
throw const ApiException(
'decodePath did not match the structure of the JSON response',
recoverySuggestion: 'Include decodePath when creating a request '
'that includes a modelType.',
);
}
dataJson = dataJson![element];
});
Expand Down
38 changes: 23 additions & 15 deletions packages/amplify_api/lib/src/graphql/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,35 @@ ModelSchema getModelSchemaByModelName(
String modelName, GraphQLRequestOperation? operation) {
final provider = AmplifyAPI.instance.getModelProvider();
if (provider == null) {
throw ApiException('No modelProvider found',
recoverySuggestion:
'Pass in a modelProvider instance while instantiating APIPlugin');
throw const ApiException(
'No modelProvider found',
recoverySuggestion:
'Pass in a modelProvider instance while instantiating APIPlugin',
);
}
final schema = (provider.modelSchemas + provider.customTypeSchemas).firstWhere(
(elem) => elem.name == modelName,
orElse: () => throw ApiException(
'No schema found for the ModelType provided: $modelName',
recoverySuggestion:
'Pass in a valid modelProvider instance while instantiating APIPlugin or provide a valid ModelType'));
final schema = (provider.modelSchemas + provider.customTypeSchemas)
.firstWhere((elem) => elem.name == modelName,
orElse: () => throw ApiException(
'No schema found for the ModelType provided: $modelName',
recoverySuggestion:
'Pass in a valid modelProvider instance while '
'instantiating APIPlugin or provide a valid ModelType',
));

if (schema.fields == null) {
throw ApiException('Schema found does not have a fields property',
recoverySuggestion:
'Pass in a valid modelProvider instance while instantiating APIPlugin');
throw const ApiException(
'Schema found does not have a fields property',
recoverySuggestion: 'Pass in a valid modelProvider instance while '
'instantiating APIPlugin',
);
}

if (operation == GraphQLRequestOperation.list && schema.pluralName == null) {
throw ApiException('No schema name found',
recoverySuggestion:
'Pass in a valid modelProvider instance while instantiating APIPlugin or provide a valid ModelType');
throw const ApiException(
'No schema name found',
recoverySuggestion: 'Pass in a valid modelProvider instance while '
'instantiating APIPlugin or provide a valid ModelType',
);
}

return schema;
Expand Down
8 changes: 3 additions & 5 deletions packages/amplify_api/test/amplify_api_mutate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import 'package:amplify_test/test_models/ModelProvider.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

// ignore_for_file: implicit_dynamic_list_literal

void main() {
const MethodChannel apiChannel = MethodChannel('com.amazonaws.amplify/api');

Expand Down Expand Up @@ -85,7 +83,7 @@ void main() {

apiChannel.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'mutate') {
return {'data': mutationResult.toString(), 'errors': []};
return {'data': mutationResult.toString(), 'errors': <Object>[]};
}
});

Expand Down Expand Up @@ -113,7 +111,7 @@ void main() {

apiChannel.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'mutate') {
return {'data': mutationResult.toString(), 'errors': []};
return {'data': mutationResult.toString(), 'errors': <Object>[]};
}
});

Expand Down Expand Up @@ -141,7 +139,7 @@ void main() {

apiChannel.setMockMethodCallHandler((MethodCall methodCall) async {
if (methodCall.method == 'mutate') {
return {'data': mutationResult.toString(), 'errors': []};
return {'data': mutationResult.toString(), 'errors': <Object>[]};
}
});

Expand Down
6 changes: 2 additions & 4 deletions packages/amplify_api/test/amplify_api_query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import 'package:amplify_test/test_models/ModelProvider.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

// ignore_for_file: implicit_dynamic_list_literal

void main() {
const MethodChannel apiChannel = MethodChannel('com.amazonaws.amplify/api');

Expand Down Expand Up @@ -105,7 +103,7 @@ void main() {
}''';

apiChannel.setMockMethodCallHandler((MethodCall methodCall) async {
return {'data': queryResult.toString(), 'errors': []};
return {'data': queryResult.toString(), 'errors': <Object>[]};
});

GraphQLRequest<Blog> req = ModelQueries.get<Blog>(Blog.classType, id);
Expand Down Expand Up @@ -152,7 +150,7 @@ void main() {
}''';

apiChannel.setMockMethodCallHandler((MethodCall methodCall) async {
return {'data': queryResult, 'errors': []};
return {'data': queryResult, 'errors': <Object>[]};
});

GraphQLRequest<PaginatedResult<Blog>> req =
Expand Down
17 changes: 11 additions & 6 deletions packages/amplify_api/test/amplify_api_subscribe_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import 'dart:async';

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_test/amplify_test.dart';
import 'package:amplify_test/test_models/ModelProvider.dart';
import 'package:async/async.dart';
import 'package:flutter/services.dart';
Expand All @@ -33,11 +34,13 @@ void main() {

/// Fires an event on the event channel from the mock platform side.
void emitValues(ByteData? event) {
ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage(
eventChannel,
event,
(ByteData? reply) {},
);
ambiguate(ServicesBinding.instance)!
.defaultBinaryMessenger
.handlePlatformMessage(
eventChannel,
event,
(ByteData? reply) {},
);
}

// Monitors calls to subscribe and cancel on the method channel.
Expand Down Expand Up @@ -73,7 +76,9 @@ void main() {
// This is mostly a no-op in these tests, since a `subscribe` event on the
// method channel is what initializes GraphQL subscriptions, not adding a listener
// to the event channel.
ServicesBinding.instance!.defaultBinaryMessenger.setMockMessageHandler(
ambiguate(ServicesBinding.instance)!
.defaultBinaryMessenger
.setMockMessageHandler(
eventChannel,
(ByteData? message) async {
final methodCall = standardCodec.decodeMethodCall(message);
Expand Down
Loading