Skip to content

Commit 650120a

Browse files
author
Travis Sheppard
committed
Merge branch 'release-candidate' into merge-rc-to-main-0.4.0
2 parents af07793 + 95cd352 commit 650120a

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed

packages/amplify_api/example/integration_test/graphql_tests.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ void main() {
202202
var secondRes = await Amplify.API.query(request: secondReq!).response;
203203
var secondData = secondRes.data;
204204
expect(secondData?.items.length, limit);
205-
expect(secondData?.items[0].id, isNot(firstData?.items[0].id));
205+
final firstId = firstData?.items[0]?.id;
206+
final secondId = secondData?.items[0]?.id;
207+
expect(firstId?.isNotEmpty, isTrue);
208+
expect(secondId?.isNotEmpty, isTrue);
209+
expect(firstId, isNot(secondId));
206210
});
207211

208212
testWidgets('should LIST blogs with Model helper with query predicate',

packages/amplify_api/lib/src/graphql/paginated_model_type_impl.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class PaginatedModelTypeImpl<T extends Model> extends PaginatedModelType<T> {
1515
}
1616

1717
final items = itemsJson
18-
.cast<Map>()
18+
.cast<Map?>()
1919
.map(
2020
// ignore: implicit_dynamic_method
21-
(e) => modelType.fromJson(e.cast()),
21+
(e) => e != null ? modelType.fromJson(e.cast()) : null,
2222
)
2323
.toList();
2424

packages/amplify_api/lib/src/graphql/paginated_result_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'package:amplify_api/src/graphql/paginated_model_type_impl.dart';
1919
import 'package:amplify_core/amplify_core.dart';
2020

2121
class PaginatedResultImpl<T extends Model> extends PaginatedResult<T> {
22-
const PaginatedResultImpl(List<T> items, int? limit, String? nextToken,
22+
const PaginatedResultImpl(List<T?> items, int? limit, String? nextToken,
2323
Map<String, dynamic>? filter)
2424
: super(items, limit, nextToken, filter);
2525

packages/amplify_api/lib/src/graphql/utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ Map<String, dynamic> transformAppSyncJsonToModelJson(
100100
// check for list at top-level and tranform each entry
101101
if (isPaginated && _input[items] is List) {
102102
final transformedItems = (_input[items] as List)
103-
.map((dynamic e) => transformAppSyncJsonToModelJson(e, modelSchema))
103+
.map((dynamic e) =>
104+
e != null ? transformAppSyncJsonToModelJson(e, modelSchema) : null)
104105
.toList();
105106
_input.update(items, (dynamic value) => transformedItems);
106107
return _input;

packages/amplify_api/test/graphql_helpers_test.dart

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,41 @@ void main() {
146146
request: req, data: data, errors: errors);
147147

148148
expect(response.data, isA<PaginatedResult<Blog>>());
149-
expect(response.data?.items, isA<List<Blog>>());
149+
expect(response.data?.items, isA<List<Blog?>>());
150150
expect(response.data?.items.length, 2);
151151
});
152152

153+
test(
154+
'ModelQueries.list() should decode gracefully when there is a null in the items list',
155+
() async {
156+
GraphQLRequest<PaginatedResult<Blog>> req =
157+
ModelQueries.list<Blog>(Blog.classType, limit: 2);
158+
159+
List<GraphQLResponseError> errors = [];
160+
String data = '''{
161+
"listBlogs": {
162+
"items": [
163+
{
164+
"id": "test-id-1",
165+
"name": "Test Blog 1",
166+
"createdAt": "2021-07-29T23:09:58.441Z"
167+
},
168+
null
169+
],
170+
"nextToken": "super-secret-next-token"
171+
}
172+
}''';
173+
174+
GraphQLResponse<PaginatedResult<Blog>> response =
175+
GraphQLResponseDecoder.instance.decode<PaginatedResult<Blog>>(
176+
request: req, data: data, errors: errors);
177+
178+
expect(response.data, isA<PaginatedResult<Blog>>());
179+
expect(response.data?.items, isA<List<Blog?>>());
180+
expect(response.data?.items.length, 2);
181+
expect(response.data?.items[1], isNull);
182+
});
183+
153184
test(
154185
'GraphQLResponse<PaginatedResult<Blog>> can get the request for next page of data',
155186
() async {
@@ -689,6 +720,36 @@ void main() {
689720
expect(output, expectedOutput);
690721
});
691722

723+
test('should translate list with a null entry to expected format', () {
724+
final input = <String, dynamic>{
725+
'items': [
726+
{
727+
'id': 'xyz456',
728+
'title': 'Lorem Ipsum',
729+
'rating': 0,
730+
'blog': {'id': 'abc123', 'title': 'blog about life'}
731+
},
732+
null
733+
]
734+
};
735+
final expectedOutput = <String, dynamic>{
736+
'items': [
737+
{
738+
'id': 'xyz456',
739+
'title': 'Lorem Ipsum',
740+
'rating': 0,
741+
'blog': {
742+
'serializedData': {'id': 'abc123', 'title': 'blog about life'}
743+
}
744+
},
745+
null
746+
]
747+
};
748+
final output = transformAppSyncJsonToModelJson(input, Post.schema,
749+
isPaginated: true);
750+
expect(output, expectedOutput);
751+
});
752+
692753
test('should result in no-op if wrong schema provided', () {
693754
final input = <String, dynamic>{
694755
'id': 'xyz456',

packages/amplify_api_plugin_interface/lib/src/types/pagination/paginated_result.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'package:amplify_core/amplify_core.dart';
1818
import '../../types.dart';
1919

2020
abstract class PaginatedResult<T extends Model> extends Model {
21-
final List<T> items;
21+
final List<T?> items;
2222
final int? limit;
2323
final String? nextToken;
2424
final Map<String, dynamic>? filter;

packages/amplify_authenticator/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ environment:
88
flutter: ">=1.17.0"
99

1010
dependencies:
11-
amplify_auth_cognito: ^0.3.0
12-
amplify_auth_plugin_interface: ^0.3.0
13-
amplify_core: ^0.3.0
14-
amplify_flutter: ^0.3.0
11+
amplify_auth_cognito: ">=0.3.0 <0.5.0"
12+
amplify_auth_plugin_interface: ">=0.3.0 <0.5.0"
13+
amplify_core: ">=0.3.0 <0.5.0"
14+
amplify_flutter: ">=0.3.0 <0.5.0"
1515
collection: ^1.15.0
1616
flutter:
1717
sdk: flutter

0 commit comments

Comments
 (0)