Skip to content

Commit

Permalink
fix(appsync-modelgen-plugin): refactor the Dart model .fromJson to ma…
Browse files Browse the repository at this point in the history
…tch appsync response

BREAKING CHANGE: Changes the decode path expectation for Dart Model .fromJson()

aws-amplify/amplify-flutter#816
  • Loading branch information
Equartey committed Apr 18, 2024
1 parent 9f55941 commit 54670ba
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 190 deletions.
24 changes: 2 additions & 22 deletions packages/appsync-modelgen-plugin/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface AppSyncModelPluginConfig extends RawDocumentsConfig {
// @public (undocumented)
export type Argument = {
name: string;
type: InputFieldType;
type: FieldType;
isArray: boolean;
isRequired: boolean;
isArrayNullable?: boolean;
Expand Down Expand Up @@ -94,27 +94,14 @@ export type FieldAttribute = ModelAttribute;
export type Fields = Record<string, Field>;

// @public (undocumented)
export type FieldType = ScalarType | {
export type FieldType = 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime' | 'AWSDateTime' | 'AWSTimestamp' | 'AWSEmail' | 'AWSURL' | 'AWSIPAddress' | 'Boolean' | 'AWSJSON' | 'AWSPhone' | {
enum: string;
} | {
model: string;
} | {
nonModel: string;
};

// @public (undocumented)
export type Input = {
name: string;
attributes: Arguments;
};

// @public (undocumented)
export type InputFieldType = ScalarType | {
enum: string;
} | {
input: string;
};

// @public (undocumented)
export type ModelAttribute = {
type: string;
Expand All @@ -132,7 +119,6 @@ export type ModelIntrospectionSchema = {
queries?: SchemaQueries;
mutations?: SchemaMutations;
subscriptions?: SchemaSubscriptions;
inputs?: SchemaInputs;
};

// Warning: (ae-forgotten-export) The symbol "RawAppSyncModelConfig" needs to be exported by the entry point index.d.ts
Expand All @@ -150,9 +136,6 @@ export type PrimaryKeyInfo = {
sortKeyFieldNames: string[];
};

// @public (undocumented)
export type ScalarType = 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime' | 'AWSDateTime' | 'AWSTimestamp' | 'AWSEmail' | 'AWSURL' | 'AWSIPAddress' | 'Boolean' | 'AWSJSON' | 'AWSPhone';

// @public (undocumented)
export type SchemaEnum = {
name: string;
Expand All @@ -162,9 +145,6 @@ export type SchemaEnum = {
// @public (undocumented)
export type SchemaEnums = Record<string, SchemaEnum>;

// @public (undocumented)
export type SchemaInputs = Record<string, Input>;

// @public (undocumented)
export type SchemaModel = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ class Post extends amplify_core.Model {
_title = json['title'],
_rating = (json['rating'] as num?)?.toInt(),
_status = amplify_core.enumFromString<PostStatus>(json['status'], PostStatus.values),
_comments = json['comments'] is List
? (json['comments'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_comments = json['comments'] != null
? (json['comments']['items'] as List)
.where((e) => e != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -333,8 +333,8 @@ class Comment extends amplify_core.Model {

Comment.fromJson(Map<String, dynamic> json)
: id = json['id'],
_post = json['post']?['serializedData'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']['serializedData']))
_post = json['post'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']))
: null,
_content = json['content'];

Expand Down Expand Up @@ -553,10 +553,10 @@ class Post extends amplify_core.Model {
_title = json['title'],
_rating = (json['rating'] as num?)?.toInt(),
_status = amplify_core.enumFromString<PostStatus>(json['status'], PostStatus.values),
_comments = json['comments'] is List
? (json['comments'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_comments = json['comments'] != null
? (json['comments']['items'] as List)
.where((e) => e != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -726,8 +726,8 @@ class Comment extends amplify_core.Model {

Comment.fromJson(Map<String, dynamic> json)
: id = json['id'],
_post = json['post']?['serializedData'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']['serializedData']))
_post = json['post'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']))
: null,
_content = json['content'];

Expand Down Expand Up @@ -1123,13 +1123,13 @@ class Contact {

Contact.fromJson(Map<String, dynamic> json)
: _contactName = json['contactName'],
_phone = json['phone']?['serializedData'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']['serializedData']))
_phone = json['phone'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']))
: null,
_mailingAddresses = json['mailingAddresses'] is List
? (json['mailingAddresses'] as List)
.where((e) => e != null)
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -1371,13 +1371,13 @@ class Person extends amplify_core.Model {
Person.fromJson(Map<String, dynamic> json)
: id = json['id'],
_name = json['name'],
_phone = json['phone']?['serializedData'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']['serializedData']))
_phone = json['phone'] != null
? Phone.fromJson(new Map<String, dynamic>.from(json['phone']))
: null,
_mailingAddresses = json['mailingAddresses'] is List
? (json['mailingAddresses'] as List)
.where((e) => e != null)
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
.map((e) => Address.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -2676,10 +2676,10 @@ class Post extends amplify_core.Model {
: id = json['id'],
_title = json['title'],
_content = json['content'],
_tags = json['tags'] is List
? (json['tags'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => PostTags.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_tags = json['tags'] != null
? (json['tags']['items'] as List)
.where((e) => e != null)
.map((e) => PostTags.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -2832,10 +2832,10 @@ class Tag extends amplify_core.Model {
Tag.fromJson(Map<String, dynamic> json)
: id = json['id'],
_label = json['label'],
_posts = json['posts'] is List
? (json['posts'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => PostTags.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_posts = json['posts'] != null
? (json['posts']['items'] as List)
.where((e) => e != null)
.map((e) => PostTags.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -2989,11 +2989,11 @@ class PostTags extends amplify_core.Model {

PostTags.fromJson(Map<String, dynamic> json)
: id = json['id'],
_post = json['post']?['serializedData'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']['serializedData']))
_post = json['post'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']))
: null,
_tag = json['tag']?['serializedData'] != null
? Tag.fromJson(new Map<String, dynamic>.from(json['tag']['serializedData']))
_tag = json['tag'] != null
? Tag.fromJson(new Map<String, dynamic>.from(json['tag']))
: null;

Map<String, dynamic> toJson() => {
Expand Down Expand Up @@ -5453,10 +5453,10 @@ class Todo extends amplify_core.Model {

Todo.fromJson(Map<String, dynamic> json)
: id = json['id'],
_tasks = json['tasks'] is List
? (json['tasks'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Task.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_tasks = json['tasks'] != null
? (json['tasks']['items'] as List)
.where((e) => e != null)
.map((e) => Task.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -5600,8 +5600,8 @@ class Task extends amplify_core.Model {

Task.fromJson(Map<String, dynamic> json)
: id = json['id'],
_todo = json['todo']?['serializedData'] != null
? Todo.fromJson(new Map<String, dynamic>.from(json['todo']['serializedData']))
_todo = json['todo'] != null
? Todo.fromJson(new Map<String, dynamic>.from(json['todo']))
: null;

Map<String, dynamic> toJson() => {
Expand Down Expand Up @@ -5776,10 +5776,10 @@ class Blog extends amplify_core.Model {
Blog.fromJson(Map<String, dynamic> json)
: id = json['id'],
_name = json['name'],
_posts = json['posts'] is List
? (json['posts'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Post.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_posts = json['posts'] != null
? (json['posts']['items'] as List)
.where((e) => e != null)
.map((e) => Post.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null,
_test = json['test']?.cast<String>();
Expand Down Expand Up @@ -5961,8 +5961,8 @@ class Comment extends amplify_core.Model {

Comment.fromJson(Map<String, dynamic> json)
: id = json['id'],
_post = json['post']?['serializedData'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']['serializedData']))
_post = json['post'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']))
: null,
_content = json['content'];

Expand Down Expand Up @@ -6150,13 +6150,13 @@ class Post extends amplify_core.Model {
Post.fromJson(Map<String, dynamic> json)
: id = json['id'],
_title = json['title'],
_blog = json['blog']?['serializedData'] != null
? Blog.fromJson(new Map<String, dynamic>.from(json['blog']['serializedData']))
_blog = json['blog'] != null
? Blog.fromJson(new Map<String, dynamic>.from(json['blog']))
: null,
_comments = json['comments'] is List
? (json['comments'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_comments = json['comments'] != null
? (json['comments']['items'] as List)
.where((e) => e != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -6685,10 +6685,10 @@ class Blog extends amplify_core.Model {
Blog.fromJson(Map<String, dynamic> json)
: id = json['id'],
_name = json['name'],
_posts = json['posts'] is List
? (json['posts'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Post.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_posts = json['posts'] != null
? (json['posts']['items'] as List)
.where((e) => e != null)
.map((e) => Post.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -6860,8 +6860,8 @@ class Comment extends amplify_core.Model {

Comment.fromJson(Map<String, dynamic> json)
: id = json['id'],
_post = json['post']?['serializedData'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']['serializedData']))
_post = json['post'] != null
? Post.fromJson(new Map<String, dynamic>.from(json['post']))
: null,
_content = json['content'];

Expand Down Expand Up @@ -7049,13 +7049,13 @@ class Post extends amplify_core.Model {
Post.fromJson(Map<String, dynamic> json)
: id = json['id'],
_title = json['title'],
_blog = json['blog']?['serializedData'] != null
? Blog.fromJson(new Map<String, dynamic>.from(json['blog']['serializedData']))
_blog = json['blog'] != null
? Blog.fromJson(new Map<String, dynamic>.from(json['blog']))
: null,
_comments = json['comments'] is List
? (json['comments'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_comments = json['comments'] != null
? (json['comments']['items'] as List)
.where((e) => e != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -7232,16 +7232,16 @@ class TestModel extends amplify_core.Model {

TestModel.fromJson(Map<String, dynamic> json)
: id = json['id'],
_listOfModels = json['listOfModels'] is List
? (json['listOfModels'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => ListItem.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_listOfModels = json['listOfModels'] != null
? (json['listOfModels']['items'] as List)
.where((e) => e != null)
.map((e) => ListItem.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null,
_nullableListOfModels = json['nullableListOfModels'] is List
? (json['nullableListOfModels'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => ListItem.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_nullableListOfModels = json['nullableListOfModels'] != null
? (json['nullableListOfModels']['items'] as List)
.where((e) => e != null)
.map((e) => ListItem.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null;

Expand Down Expand Up @@ -9979,10 +9979,10 @@ class Post extends amplify_core.Model {
Post.fromJson(Map<String, dynamic> json)
: id = json['id'],
_title = json['title'],
_comments = json['comments'] is List
? (json['comments'] as List)
.where((e) => e?['serializedData'] != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e['serializedData'])))
_comments = json['comments'] != null
? (json['comments']['items'] as List)
.where((e) => e != null)
.map((e) => Comment.fromJson(new Map<String, dynamic>.from(e)))
.toList()
: null,
_createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null,
Expand Down Expand Up @@ -10575,8 +10575,8 @@ class Project extends amplify_core.Model {
Project.fromJson(Map<String, dynamic> json)
: _projectId = json['projectId'],
_name = json['name'],
_team = json['team']?['serializedData'] != null
? Team.fromJson(new Map<String, dynamic>.from(json['team']['serializedData']))
_team = json['team'] != null
? Team.fromJson(new Map<String, dynamic>.from(json['team']))
: null,
_createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null,
_updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null,
Expand Down Expand Up @@ -10882,8 +10882,8 @@ class Team extends amplify_core.Model {
Team.fromJson(Map<String, dynamic> json)
: _teamId = json['teamId'],
_name = json['name'],
_project = json['project']?['serializedData'] != null
? Project.fromJson(new Map<String, dynamic>.from(json['project']['serializedData']))
_project = json['project'] != null
? Project.fromJson(new Map<String, dynamic>.from(json['project']))
: null,
_createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null,
_updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null;
Expand Down Expand Up @@ -11179,8 +11179,8 @@ class CpkOneToOneBidirectionalParent extends amplify_core.Model {
CpkOneToOneBidirectionalParent.fromJson(Map<String, dynamic> json)
: id = json['id'],
_name = json['name'],
_explicitChild = json['explicitChild']?['serializedData'] != null
? CpkOneToOneBidirectionalChildExplicit.fromJson(new Map<String, dynamic>.from(json['explicitChild']['serializedData']))
_explicitChild = json['explicitChild'] != null
? CpkOneToOneBidirectionalChildExplicit.fromJson(new Map<String, dynamic>.from(json['explicitChild']))
: null,
_createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null,
_updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null,
Expand Down Expand Up @@ -11469,8 +11469,8 @@ class CpkOneToOneBidirectionalChildExplicit extends amplify_core.Model {
CpkOneToOneBidirectionalChildExplicit.fromJson(Map<String, dynamic> json)
: id = json['id'],
_name = json['name'],
_belongsToParent = json['belongsToParent']?['serializedData'] != null
? CpkOneToOneBidirectionalParent.fromJson(new Map<String, dynamic>.from(json['belongsToParent']['serializedData']))
_belongsToParent = json['belongsToParent'] != null
? CpkOneToOneBidirectionalParent.fromJson(new Map<String, dynamic>.from(json['belongsToParent']))
: null,
_createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null,
_updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null;
Expand Down
Loading

0 comments on commit 54670ba

Please sign in to comment.