Skip to content

Commit 7343f15

Browse files
committed
Merge remote-tracking branch 'origin/manyToMany-fix' into manyToMany-fix
2 parents d74d8a0 + bf60e1f commit 7343f15

File tree

17 files changed

+353
-59
lines changed

17 files changed

+353
-59
lines changed

packages/amplify-codegen/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [2.26.9](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@2.26.9) (2021-10-27)
7+
8+
**Note:** Version bump only for package amplify-codegen
9+
10+
11+
12+
13+
14+
## [2.26.8](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@2.26.8) (2021-10-21)
15+
16+
**Note:** Version bump only for package amplify-codegen
17+
18+
19+
20+
21+
622
## [2.26.7](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@2.26.7) (2021-10-05)
723

824
**Note:** Version bump only for package amplify-codegen

packages/amplify-codegen/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amplify-codegen",
3-
"version": "2.26.7",
3+
"version": "2.26.9",
44
"description": "amplify code generator",
55
"repository": {
66
"type": "git",
@@ -20,9 +20,9 @@
2020
"test-watch": "jest --watch"
2121
},
2222
"dependencies": {
23-
"@aws-amplify/appsync-modelgen-plugin": "1.29.0",
24-
"@aws-amplify/graphql-docs-generator": "2.3.4",
25-
"@aws-amplify/graphql-types-generator": "2.8.2",
23+
"@aws-amplify/appsync-modelgen-plugin": "1.29.1",
24+
"@aws-amplify/graphql-docs-generator": "2.4.0",
25+
"@aws-amplify/graphql-types-generator": "2.8.3",
2626
"@graphql-codegen/core": "1.8.3",
2727
"amplify-codegen-appsync-model-plugin": "^1.22.3",
2828
"amplify-graphql-docs-generator": "^2.2.1",

packages/amplify-codegen/src/walkthrough/questions/maxDepth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const inquirer = require('inquirer');
22

33
const constants = require('../../constants');
44

5-
async function askMaxDepth(defaultDepth = 3) {
5+
async function askMaxDepth(defaultDepth = 2) {
66
const answer = await inquirer.prompt([
77
{
88
name: 'maxDepth',

packages/appsync-modelgen-plugin/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [1.29.1](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2021-10-21)
7+
8+
9+
### Bug Fixes
10+
11+
* **appsync-modelgen-plugin:** non model type with id field in java ([#260](https://github.com/aws-amplify/amplify-codegen/issues/260)) ([186f8cd](https://github.com/aws-amplify/amplify-codegen/commit/186f8cdc6be4657e8dc061ee19430d0dccbaebdb))
12+
13+
14+
15+
16+
617
# [1.29.0](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2021-10-05)
718

819

packages/appsync-modelgen-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aws-amplify/appsync-modelgen-plugin",
3-
"version": "1.29.0",
3+
"version": "1.29.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/aws-amplify/amplify-codegen.git",

packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,125 @@ public final class Location {
26052605
"
26062606
`;
26072607

2608+
exports[`AppSyncModelVisitor Non model type should generate class for non model types with id field 1`] = `
2609+
"package com.amplifyframework.datastore.generated.model;
2610+
2611+
2612+
import androidx.core.util.ObjectsCompat;
2613+
2614+
import java.util.Objects;
2615+
import java.util.List;
2616+
2617+
/** This is an auto generated class representing the Reference type in your schema. */
2618+
public final class Reference {
2619+
private final String id;
2620+
private final ReferenceIdTypeEnum idType;
2621+
public String getId() {
2622+
return id;
2623+
}
2624+
2625+
public ReferenceIdTypeEnum getIdType() {
2626+
return idType;
2627+
}
2628+
2629+
private Reference(String id, ReferenceIdTypeEnum idType) {
2630+
this.id = id;
2631+
this.idType = idType;
2632+
}
2633+
2634+
@Override
2635+
public boolean equals(Object obj) {
2636+
if (this == obj) {
2637+
return true;
2638+
} else if(obj == null || getClass() != obj.getClass()) {
2639+
return false;
2640+
} else {
2641+
Reference reference = (Reference) obj;
2642+
return ObjectsCompat.equals(getId(), reference.getId()) &&
2643+
ObjectsCompat.equals(getIdType(), reference.getIdType());
2644+
}
2645+
}
2646+
2647+
@Override
2648+
public int hashCode() {
2649+
return new StringBuilder()
2650+
.append(getId())
2651+
.append(getIdType())
2652+
.toString()
2653+
.hashCode();
2654+
}
2655+
2656+
public static IdStep builder() {
2657+
return new Builder();
2658+
}
2659+
2660+
public CopyOfBuilder copyOfBuilder() {
2661+
return new CopyOfBuilder(id,
2662+
idType);
2663+
}
2664+
public interface IdStep {
2665+
IdTypeStep id(String id);
2666+
}
2667+
2668+
2669+
public interface IdTypeStep {
2670+
BuildStep idType(ReferenceIdTypeEnum idType);
2671+
}
2672+
2673+
2674+
public interface BuildStep {
2675+
Reference build();
2676+
}
2677+
2678+
2679+
public static class Builder implements IdStep, IdTypeStep, BuildStep {
2680+
private String id;
2681+
private ReferenceIdTypeEnum idType;
2682+
@Override
2683+
public Reference build() {
2684+
2685+
return new Reference(
2686+
id,
2687+
idType);
2688+
}
2689+
2690+
@Override
2691+
public IdTypeStep id(String id) {
2692+
Objects.requireNonNull(id);
2693+
this.id = id;
2694+
return this;
2695+
}
2696+
2697+
@Override
2698+
public BuildStep idType(ReferenceIdTypeEnum idType) {
2699+
Objects.requireNonNull(idType);
2700+
this.idType = idType;
2701+
return this;
2702+
}
2703+
}
2704+
2705+
2706+
public final class CopyOfBuilder extends Builder {
2707+
private CopyOfBuilder(String id, ReferenceIdTypeEnum idType) {
2708+
super.id(id)
2709+
.idType(idType);
2710+
}
2711+
2712+
@Override
2713+
public CopyOfBuilder id(String id) {
2714+
return (CopyOfBuilder) super.id(id);
2715+
}
2716+
2717+
@Override
2718+
public CopyOfBuilder idType(ReferenceIdTypeEnum idType) {
2719+
return (CopyOfBuilder) super.idType(idType);
2720+
}
2721+
}
2722+
2723+
}
2724+
"
2725+
`;
2726+
26082727
exports[`AppSyncModelVisitor One to Many connection with no nullable and non nullable fields should generate class for many side of the connection 1`] = `
26092728
"package com.amplifyframework.datastore.generated.model;
26102729

packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,37 @@ const buildSchemaWithDirectives = (schema: String): GraphQLSchema => {
99
return buildSchema([schema, directives, scalars].join('\n'));
1010
};
1111

12-
const getVisitor = (schema: string, selectedType?: string, generate: CodeGenGenerateEnum = CodeGenGenerateEnum.code, transformerVersion: number = 1) => {
12+
13+
const getVisitor = (
14+
schema: string,
15+
selectedType?: string,
16+
generate: CodeGenGenerateEnum = CodeGenGenerateEnum.code,
17+
transformerVersion: number = 1,
18+
) => {
1319
const ast = parse(schema);
1420
const builtSchema = buildSchemaWithDirectives(schema);
1521
const visitor = new AppSyncModelJavaVisitor(
1622
builtSchema,
17-
{ directives, target: 'android', generate, scalars: JAVA_SCALAR_MAP, isTimestampFieldsAdded: true, handleListNullabilityTransparently: true, transformerVersion: transformerVersion },
23+
{
24+
directives,
25+
target: 'android',
26+
generate,
27+
scalars: JAVA_SCALAR_MAP,
28+
isTimestampFieldsAdded: true,
29+
handleListNullabilityTransparently: true,
30+
transformerVersion: transformerVersion,
31+
},
1832
{ selectedType },
1933
);
2034
visit(ast, { leave: visitor });
2135
return visitor;
2236
};
2337

24-
const getVisitorPipelinedTransformer = (schema: string, selectedType?: string, generate: CodeGenGenerateEnum = CodeGenGenerateEnum.code) => {
38+
const getVisitorPipelinedTransformer = (
39+
schema: string,
40+
selectedType?: string,
41+
generate: CodeGenGenerateEnum = CodeGenGenerateEnum.code,
42+
) => {
2543
return getVisitor(schema, selectedType, generate, 2);
2644
};
2745

@@ -98,7 +116,7 @@ describe('AppSyncModelVisitor', () => {
98116
it('Should generate a class a model with all optional fields except id field', () => {
99117
const schema = /* GraphQL */ `
100118
type SimpleModel @model {
101-
id: ID!,
119+
id: ID!
102120
name: String
103121
bar: String
104122
}
@@ -196,23 +214,23 @@ describe('AppSyncModelVisitor', () => {
196214
describe('vNext transformer feature parity tests', () => {
197215
it('should produce the same result for @primaryKey as the primary key variant of @key', async () => {
198216
const schemaV1 = /* GraphQL */ `
199-
type authorBook @model @key(fields: ["author_id"]) {
200-
id: ID!
201-
author_id: ID!
202-
book_id: ID!
203-
author: String
204-
book: String
205-
}
206-
`;
217+
type authorBook @model @key(fields: ["author_id"]) {
218+
id: ID!
219+
author_id: ID!
220+
book_id: ID!
221+
author: String
222+
book: String
223+
}
224+
`;
207225
const schemaV2 = /* GraphQL */ `
208-
type authorBook @model {
209-
id: ID!
210-
author_id: ID! @primaryKey
211-
book_id: ID!
212-
author: String
213-
book: String
214-
}
215-
`;
226+
type authorBook @model {
227+
id: ID!
228+
author_id: ID! @primaryKey
229+
book_id: ID!
230+
author: String
231+
book: String
232+
}
233+
`;
216234
const visitorV1 = getVisitor(schemaV1, 'authorBook');
217235
const visitorV2 = getVisitorPipelinedTransformer(schemaV2, 'authorBook');
218236
const version1Code = visitorV1.generate();
@@ -223,23 +241,23 @@ describe('AppSyncModelVisitor', () => {
223241

224242
it('should produce the same result for @index as the secondary index variant of @key', async () => {
225243
const schemaV1 = /* GraphQL */ `
226-
type authorBook @model @key(fields: ["id"]) @key(name: "authorSecondary", fields: ["author_id", "author"]) {
227-
id: ID!
228-
author_id: ID!
229-
book_id: ID!
230-
author: String
231-
book: String
232-
}
233-
`;
244+
type authorBook @model @key(fields: ["id"]) @key(name: "authorSecondary", fields: ["author_id", "author"]) {
245+
id: ID!
246+
author_id: ID!
247+
book_id: ID!
248+
author: String
249+
book: String
250+
}
251+
`;
234252
const schemaV2 = /* GraphQL */ `
235-
type authorBook @model {
236-
id: ID! @primaryKey
237-
author_id: ID! @index(name: "authorSecondary", sortKeyFields: ["author"])
238-
book_id: ID!
239-
author: String
240-
book: String
241-
}
242-
`;
253+
type authorBook @model {
254+
id: ID! @primaryKey
255+
author_id: ID! @index(name: "authorSecondary", sortKeyFields: ["author"])
256+
book_id: ID!
257+
author: String
258+
book: String
259+
}
260+
`;
243261
const visitorV1 = getVisitor(schemaV1, 'authorBook');
244262
const visitorV2 = getVisitorPipelinedTransformer(schemaV2, 'authorBook');
245263
const version1Code = visitorV1.generate();
@@ -260,9 +278,7 @@ describe('AppSyncModelVisitor', () => {
260278
name: String
261279
}
262280
263-
type ListContainer
264-
@model
265-
{
281+
type ListContainer @model {
266282
id: ID!
267283
name: String
268284
list: [Int]
@@ -383,11 +399,11 @@ describe('AppSyncModelVisitor', () => {
383399

384400
it('should generate class with non-default providers', () => {
385401
const schema = /* GraphQL */ `
386-
type Employee @model @auth(rules: [{ allow: owner }, { allow: private, provider:"iam" } ]) {
402+
type Employee @model @auth(rules: [{ allow: owner }, { allow: private, provider: "iam" }]) {
387403
id: ID!
388404
name: String!
389405
address: String!
390-
ssn: String @auth(rules: [{ allow: groups, provider:"oidc", groups: ["Admins"] }])
406+
ssn: String @auth(rules: [{ allow: groups, provider: "oidc", groups: ["Admins"] }])
391407
}
392408
`;
393409
const visitor = getVisitor(schema, 'Employee');
@@ -453,6 +469,16 @@ describe('AppSyncModelVisitor', () => {
453469
lang: String!
454470
}
455471
`;
472+
const nonModelwithIdSchema = /* GraphQL */ `
473+
enum ReferenceIdTypeEnum {
474+
ASIN
475+
OBJECT_ID
476+
}
477+
type Reference {
478+
id: String!
479+
idType: ReferenceIdTypeEnum!
480+
}
481+
`;
456482
it('should generate class for non model types', () => {
457483
const visitor = getVisitor(schema, 'Location');
458484
const generatedCode = visitor.generate();
@@ -465,6 +491,12 @@ describe('AppSyncModelVisitor', () => {
465491
expect(() => validateJava(generatedCode)).not.toThrow();
466492
expect(generatedCode).toMatchSnapshot();
467493
});
494+
it('should generate class for non model types with id field', () => {
495+
const visitor = getVisitor(nonModelwithIdSchema, 'Reference');
496+
const generatedCode = visitor.generate();
497+
expect(() => validateJava(generatedCode)).not.toThrow();
498+
expect(generatedCode).toMatchSnapshot();
499+
});
468500
});
469501

470502
it('should generate Temporal type for AWSDate* scalars', () => {

0 commit comments

Comments
 (0)