Skip to content

Commit

Permalink
Merge github.com:aws-amplify/amplify-codegen into stocaaro/feat/sync-…
Browse files Browse the repository at this point in the history
…codegen/main
  • Loading branch information
stocaaro committed Oct 21, 2024
2 parents 952f1f2 + 85ccc89 commit f8fc0de
Show file tree
Hide file tree
Showing 20 changed files with 569 additions and 37 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
"graphql": "15.8.0",
"xml2js": "0.5.0",
"axios": "^1.7.4",
"**/@aws-amplify/amplify-codegen-e2e-tests/**/fast-xml-parser": "^4.4.1"
"**/@aws-amplify/amplify-codegen-e2e-tests/**/fast-xml-parser": "^4.4.1",
"**/@aws-amplify/amplify-codegen-e2e-tests/**/cookie": "^0.7.0"
},
"config": {
"commitizen": {
Expand Down
4 changes: 4 additions & 0 deletions packages/amplify-codegen-e2e-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.6.6](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2024-10-17)

**Note:** Version bump only for package @aws-amplify/amplify-codegen-e2e-core

## [1.6.5](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2024-05-06)

**Note:** Version bump only for package @aws-amplify/amplify-codegen-e2e-core
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-codegen-e2e-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/amplify-codegen-e2e-core",
"version": "1.6.5",
"version": "1.6.6",
"description": "",
"repository": {
"type": "git",
Expand Down
19 changes: 16 additions & 3 deletions packages/amplify-codegen-e2e-core/src/init/initProjectHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nspawn as spawn, getCLIPath, singleSelect, addCITags } from '..';
import { KEY_DOWN_ARROW, AmplifyFrontend } from '../utils';
import { KEY_DOWN_ARROW, AmplifyFrontend, ExecutionContext } from '../utils';
import { amplifyRegions } from '../configure';
import { v4 as uuid } from 'uuid';

Expand Down Expand Up @@ -44,6 +44,7 @@ export function initJSProjectWithProfile(cwd: string, settings: Object = {}): Pr

return new Promise((resolve, reject) => {
const chain = spawn(getCLIPath(), cliArgs, { cwd, stripColors: true, env, disableCIDetection: s.disableCIDetection })
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -91,19 +92,28 @@ export function initJSProjectWithProfile(cwd: string, settings: Object = {}): Pr
});
}

export const confirmUsingGen1Amplify = (executionContext: ExecutionContext): ExecutionContext => {
return executionContext
.wait('Do you want to continue with Amplify Gen 1?')
.sendConfirmYes()
.wait('Why would you like to use Amplify Gen 1?')
.sendCarriageReturn()
}

export function initAndroidProjectWithProfile(cwd: string, settings: Object): Promise<void> {
const s = { ...defaultSettings, ...settings };

addCITags(cwd);

return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['init'], {
const chain = spawn(getCLIPath(), ['init'], {
cwd,
stripColors: true,
env: {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -141,13 +151,14 @@ export function initIosProjectWithProfile(cwd: string, settings: Object): Promis
addCITags(cwd);

return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['init'], {
const chain = spawn(getCLIPath(), ['init'], {
cwd,
stripColors: true,
env: {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -178,6 +189,7 @@ export function initFlutterProjectWithProfile(cwd: string, settings: Object): Pr

return new Promise((resolve, reject) => {
let chain = spawn(getCLIPath(), ['init'], { cwd, stripColors: true })
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down Expand Up @@ -228,6 +240,7 @@ export function initProjectWithAccessKey(
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendLine(s.name)
.wait('Initialize the project with the above configuration?')
Expand Down
3 changes: 2 additions & 1 deletion packages/amplify-codegen-e2e-core/src/utils/pinpoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pinpoint } from 'aws-sdk';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions, addCITags, KEY_DOWN_ARROW } from '..';
import { getCLIPath, nspawn as spawn, singleSelect, amplifyRegions, addCITags, KEY_DOWN_ARROW, confirmUsingGen1Amplify } from '..';
import _ from 'lodash';

const settings = {
Expand Down Expand Up @@ -80,6 +80,7 @@ export function initProjectForPinpoint(cwd: string): Promise<void> {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendLine(settings.name)
.wait('Initialize the project with the above configuration?')
Expand Down
4 changes: 4 additions & 0 deletions packages/amplify-codegen-e2e-tests/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.45.4](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2024-10-17)

**Note:** Version bump only for package @aws-amplify/amplify-codegen-e2e-tests

## [2.45.3](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2024-09-05)

**Note:** Version bump only for package @aws-amplify/amplify-codegen-e2e-tests
Expand Down
6 changes: 3 additions & 3 deletions packages/amplify-codegen-e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/amplify-codegen-e2e-tests",
"version": "2.45.3",
"version": "2.45.4",
"description": "",
"repository": {
"type": "git",
Expand All @@ -23,8 +23,8 @@
"clean-e2e-resources": "ts-node ./src/cleanup-e2e-resources.ts"
},
"dependencies": {
"@aws-amplify/amplify-codegen-e2e-core": "1.6.5",
"@aws-amplify/graphql-schema-test-library": "^2.2.28",
"@aws-amplify/amplify-codegen-e2e-core": "1.6.6",
"@aws-amplify/graphql-schema-test-library": "^3.0.0",
"amazon-cognito-identity-js": "^6.3.6",
"aws-amplify": "^5.3.3",
"aws-appsync": "^4.1.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { nspawn as spawn, getCLIPath, singleSelect, amplifyRegions, addCITags, KEY_DOWN_ARROW } from '@aws-amplify/amplify-codegen-e2e-core';
import { nspawn as spawn, getCLIPath, singleSelect, amplifyRegions, addCITags, KEY_DOWN_ARROW, confirmUsingGen1Amplify } from '@aws-amplify/amplify-codegen-e2e-core';
import fs from 'fs-extra';
import os from 'os';

Expand Down Expand Up @@ -52,6 +52,7 @@ async function initWorkflow(cwd: string, settings: { accessKeyId: string; secret
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
confirmUsingGen1Amplify(chain)
.wait('Enter a name for the project')
.sendCarriageReturn()
.wait('Initialize the project with the above configuration?')
Expand Down
4 changes: 4 additions & 0 deletions packages/amplify-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [4.9.7](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.9.7) (2024-10-03)

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

## [4.9.6](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.9.6) (2024-09-26)

**Note:** Version bump only for package amplify-codegen
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amplify-codegen",
"version": "4.9.6",
"version": "4.9.7",
"description": "Amplify Code Generator",
"repository": {
"type": "git",
Expand All @@ -23,7 +23,7 @@
"dependencies": {
"@aws-amplify/graphql-directives": "^1.0.1",
"@aws-amplify/graphql-docs-generator": "4.2.1",
"@aws-amplify/graphql-generator": "0.4.6",
"@aws-amplify/graphql-generator": "0.4.7",
"@aws-amplify/graphql-types-generator": "3.6.0",
"@graphql-codegen/core": "^2.6.6",
"chalk": "^3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/appsync-modelgen-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.13.2](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2024-10-03)

### Bug Fixes

- allow required uni-directional hasOne with [@connection](https://github.com/connection) when datastore is disabled ([#888](https://github.com/aws-amplify/amplify-codegen/issues/888)) ([648f2ed](https://github.com/aws-amplify/amplify-codegen/commit/648f2edd3393ba694eef0e40af43b2bad159104d))

## [2.13.1](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2024-09-26)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/appsync-modelgen-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/appsync-modelgen-plugin",
"version": "2.13.1",
"version": "2.13.2",
"repository": {
"type": "git",
"url": "https://github.com/aws-amplify/amplify-codegen.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('process connection', () => {

it('should return HAS_MANY for Post.comments field connection info', () => {
const commentsField = modelMap.Post.fields[0];
const connectionInfo = (processConnections(commentsField, modelMap.Post, modelMap) as any) as CodeGenFieldConnectionHasMany;
const connectionInfo = (processConnections(commentsField, modelMap.Post, modelMap, true) as any) as CodeGenFieldConnectionHasMany;
expect(connectionInfo).toBeDefined();

expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_MANY);
Expand All @@ -66,7 +66,7 @@ describe('process connection', () => {

it('should return BELONGS_TO for Comment.post field connection info', () => {
const postField = modelMap.Comment.fields[0];
const connectionInfo = (processConnections(postField, modelMap.Comment, modelMap) as any) as CodeGenFieldConnectionBelongsTo;
const connectionInfo = (processConnections(postField, modelMap.Comment, modelMap, true) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();

expect(connectionInfo.kind).toEqual(CodeGenConnectionType.BELONGS_TO);
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('process connection', () => {

it('should return HAS_ONE Person.license field', () => {
const licenseField = modelMap.Person.fields[0];
const connectionInfo = (processConnections(licenseField, modelMap.Person, modelMap) as any) as CodeGenFieldConnectionHasOne;
const connectionInfo = (processConnections(licenseField, modelMap.Person, modelMap, true) as any) as CodeGenFieldConnectionHasOne;
expect(connectionInfo).toBeDefined();
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_ONE);
expect(connectionInfo.associatedWith).toEqual(modelMap.License.fields[0]);
Expand All @@ -130,7 +130,7 @@ describe('process connection', () => {

it('should return BELONGS_TO License.person field', () => {
const personField = modelMap.License.fields[0];
const connectionInfo = (processConnections(personField, modelMap.License, modelMap) as any) as CodeGenFieldConnectionBelongsTo;
const connectionInfo = (processConnections(personField, modelMap.License, modelMap, true) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.BELONGS_TO);
expect(connectionInfo.isConnectingFieldAutoCreated).toEqual(true);
Expand All @@ -141,9 +141,98 @@ describe('process connection', () => {
// Make person field optional
personField.isNullable = true;
expect(() => {
processConnections(personField, modelMap.License, modelMap);
processConnections(personField, modelMap.License, modelMap, true);
}).toThrowError('DataStore does not support 1 to 1 connection with both sides of connection as optional field');
});

describe('Uni-directional connection', () => {
const schema = /* GraphQL */ `
type User @model {
id: ID!
}
type Session @model {
id: ID!
sessionUserId: ID!
user: User! @connection(fields: ["sessionUserId"])
}
`;

const modelMap: CodeGenModelMap = {
User: {
name: 'User',
type: 'model',
directives: [],
fields: [
{
type: 'ID',
isNullable: false,
isList: false,
name: 'id',
directives: [],
},
],
},
Session: {
name: 'Session',
type: 'model',
directives: [],
fields: [
{
type: 'ID',
isNullable: false,
isList: false,
name: 'id',
directives: [],
},
{
type: 'ID',
isNullable: false,
isList: false,
name: 'sessionUserId',
directives: [],
},
{
type: 'User',
isNullable: false,
isList: false,
name: 'user',
directives: [{ name: 'connection', arguments: { fields: ['sessionUserId'] } }],
},
],
},
};

it('uni-directional One:One connection with required field and datastore is not enabled', () => {
const connectionInfo = (processConnections(modelMap.Session.fields[2], modelMap.User, modelMap, false) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_ONE);
expect(connectionInfo.isConnectingFieldAutoCreated).toEqual(false);
});

it('uni-directional One:One connection with optional field and datastore is not enabled', () => {
const field = { ...modelMap.Session.fields[2] };
field.isNullable = true;
const connectionInfo = (processConnections(field, modelMap.User, modelMap, false) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_ONE);
expect(connectionInfo.isConnectingFieldAutoCreated).toEqual(false);
});

it('uni-directional One:One connection with required field and datastore is enabled', () => {
expect(() => {
processConnections(modelMap.Session.fields[2], modelMap.User, modelMap, true);
}).toThrowError('DataStore does not support 1 to 1 connection with both sides of connection as optional field');
});

it('uni-directional One:One connection with optional field and datastore is enabled', () => {
const field = { ...modelMap.Session.fields[2] };
field.isNullable = true;
const connectionInfo = (processConnections(field, modelMap.User, modelMap, true) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_ONE);
expect(connectionInfo.isConnectingFieldAutoCreated).toEqual(false);
});
});
});
});
describe('Uni-directional connection (unnamed connection)', () => {
Expand Down Expand Up @@ -192,7 +281,7 @@ describe('process connection', () => {

it('should return HAS_MANY for Post.comments', () => {
const commentsField = modelMap.Post.fields[0];
const connectionInfo = (processConnections(commentsField, modelMap.Post, modelMap) as any) as CodeGenFieldConnectionHasMany;
const connectionInfo = (processConnections(commentsField, modelMap.Post, modelMap, true) as any) as CodeGenFieldConnectionHasMany;
expect(connectionInfo).toBeDefined();

expect(connectionInfo.kind).toEqual(CodeGenConnectionType.HAS_MANY);
Expand All @@ -208,7 +297,7 @@ describe('process connection', () => {

it('should return BELONGS_TO for Comment.post', () => {
const commentsField = modelMap.Comment.fields[0];
const connectionInfo = (processConnections(commentsField, modelMap.Comment, modelMap) as any) as CodeGenFieldConnectionBelongsTo;
const connectionInfo = (processConnections(commentsField, modelMap.Comment, modelMap, true) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();

expect(connectionInfo.kind).toEqual(CodeGenConnectionType.BELONGS_TO);
Expand Down Expand Up @@ -280,12 +369,12 @@ describe('process connection', () => {

it('should not throw error if connection directive has keyName', () => {
const commentsField = modelMap.Post.fields[0];
expect(() => processConnections(commentsField, modelMap.Post, modelMap)).not.toThrowError();
expect(() => processConnections(commentsField, modelMap.Post, modelMap, true)).not.toThrowError();
});

it('should support connection with @key on BELONGS_TO side', () => {
const postField = modelMap.Comment.fields[2];
const connectionInfo = (processConnections(postField, modelMap.Post, modelMap) as any) as CodeGenFieldConnectionBelongsTo;
const connectionInfo = (processConnections(postField, modelMap.Post, modelMap, true) as any) as CodeGenFieldConnectionBelongsTo;
expect(connectionInfo).toBeDefined();
expect(connectionInfo.kind).toEqual(CodeGenConnectionType.BELONGS_TO);
expect(connectionInfo.targetName).toEqual(modelMap.Comment.fields[0].name);
Expand Down Expand Up @@ -462,4 +551,4 @@ describe('process connection', () => {
expect(getConnectedField(subordinateField, employeeModel, employeeModel)).toEqual(supervisorField);
});
});
});
});
Loading

0 comments on commit f8fc0de

Please sign in to comment.