Skip to content

Commit

Permalink
Merge pull request #1538 from aws-amplify/main
Browse files Browse the repository at this point in the history
chore(api): trigger release pipeline
  • Loading branch information
AaronZyLee authored Jun 5, 2023
2 parents 529f17d + de6afb2 commit 33a8dd6
Show file tree
Hide file tree
Showing 58 changed files with 733 additions and 597 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
executors:
linux: &linux-e2e-executor
docker:
- image: public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:latest
- image: public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:node18
working_directory: ~/repo
resource_class: large
environment:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
equal:
- docker:
- image: >-
public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:latest
public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:node18
working_directory: ~/repo
resource_class: large
environment:
Expand All @@ -90,7 +90,7 @@ jobs:
paths: .
cleanup_resources:
docker:
- image: public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:latest
- image: public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:node18
working_directory: ~/repo
resource_class: large
environment:
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
path: ~/repo/packages/amplify-e2e-tests/amplify-e2e-reports
publish_to_local_registry:
docker:
- image: public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:latest
- image: public.ecr.aws/j4f5f3h7/amplify-cli-e2e-base-image-repo-public:node18
working_directory: ~/repo
resource_class: large
environment:
Expand Down
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Data team has general approval permissions
* @aws-amplify/amplify-data

# API approval - public surface and dependencies.
**/API.md @aws-amplify/amplify-data-admins
29 changes: 27 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Our work is done directly on Github and PR's are sent to the github repo by core

This section should get you running with **Amplify API Category** and get you familiar with the basics of the codebase.

### Local Environment Setup
### Local Development

#### Environment Setup

1. Ensure you have [Node.js](https://nodejs.org/en/download/) installed, which comes bundled with [`npm`](https://github.com/npm/cli). Use it to install or upgrade [`yarn`](https://classic.yarnpkg.com/en/docs/install):

Expand Down Expand Up @@ -60,7 +62,22 @@ This section should get you running with **Amplify API Category** and get you fa
cd amplify-category-api
```

1. Then, you can run the `setup-dev` script, which installs dependencies and performs initial configuration:
#### Building and Running Tests

1. To build local packages and verify your change is valid and doesn't break the build, you can run :
```sh
yarn # Install all dependencies for the workspace
yarn build # Build all packages in the repo
yarn test # Run tests for all packages in the repo
```
1. Note: once you've run an initial `yarn` unless you're changing dependencies in a package, re-running should not be necessary.
1. After an initial build, if you're testing changes to a single package, you can run `yarn build` and `yarn test` specifically from that directory (e.g. `/packages/amplify-graphql-model-transformer`) in order to speed up your iteration cycle.

#### Building the CLI Locally for functional testing

1. You can run the `setup-dev` script, which installs dependencies and performs initial configuration:

```sh
# Linux / macOS
Expand All @@ -70,6 +87,14 @@ This section should get you running with **Amplify API Category** and get you fa
yarn setup-dev-win
```

1. Ensure amplify-dev exists on your path.

```sh
yarn global bin # Update your `$PATH` to include this directory.
```

1. To update your local `amplify-dev` executable, you can simply `yarn build` the specific package you're editing, and those changes will be reflected automatically in the dev target.
> NOTE: Make sure to always [sync your fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork) with _main_ branch of amplify-category-api
### Architecture of the codebase
Expand Down
78 changes: 78 additions & 0 deletions depcheck.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* README
* This file contains a subset of critical dependency validation rules for the transformer packages.
* There are certain dependencies we need to be careful of introducing as we refactor the transformers,
* including access to @aws-amplify/* namespaced packages (namely core, printer),
* but we also wish to limit imports to `fs`, and a few other particular places.
*/

// List of v2 transformer directories.
const GQL_V2_TRANSFORMER_PACKAGES = [
'amplify-graphql-auth-transformer',
'amplify-graphql-default-value-transformer',
'amplify-graphql-function-transformer',
'amplify-graphql-http-transformer',
'amplify-graphql-index-transformer',
'amplify-graphql-maps-to-transformer',
'amplify-graphql-model-transformer',
'amplify-graphql-predictions-transformer',
'amplify-graphql-relational-transformer',
'amplify-graphql-searchable-transformer',
'amplify-graphql-transformer-core',
'amplify-graphql-transformer-interfaces',
'graphql-transformer-common',
'graphql-mapping-template',
];

const TRANSFORMER_RESTRICTED_IMPORTS = [
'fs',
'fs-extra',
'@aws-amplify/amplify-cli-core',
'@aws-amplify/amplify-prompts',
];

module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
env: {
es6: true,
node: true,
jest: true,
},
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
arrowFunctions: true,
modules: true,
module: true,
},
project: ['tsconfig.base.json'],
},
plugins: ['@typescript-eslint'],
settings: {
'import/parsers': { '@typescript-eslint/parser': ['.ts', '.tsx'] },
'import/resolver': { typescript: {} },
},
ignorePatterns: [
'__tests__/**',
'*.test.ts',
'lib/**',
'node_modules',
'*/node_modules',
],
overrides: [
{
files: GQL_V2_TRANSFORMER_PACKAGES.map((packageName) => `packages/${packageName}/src/**`),
excludedFiles: [
'__tests__/**',
'*.test.ts',
],
rules: {
'no-restricted-imports': ['error', ...TRANSFORMER_RESTRICTED_IMPORTS.map((importName) => ({
name: importName,
message: `${importName} is not allowed in transformer v2 packages`,
}))],
},
},
],
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"update-cli-packages": "./scripts/update-cli-dependencies.sh && yarn",
"extract-api": "lerna run extract-api",
"verify-api-extract": "yarn extract-api && ./scripts/verify-extract-api.sh",
"verify-yarn-lock": "./scripts/verify-yarn-lock.sh"
"verify-yarn-lock": "./scripts/verify-yarn-lock.sh",
"lint-deps": "git diff --name-only --cached --diff-filter d | grep -E '\\.(js|jsx|ts|tsx)$' | xargs eslint --no-eslintrc --config depcheck.config.js"
},
"bugs": {
"url": "https://github.com/aws-amplify/amplify-category-api/issues"
Expand All @@ -62,7 +63,7 @@
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "yarn verify-commit && yarn lint-fix"
"pre-commit": "yarn verify-commit && yarn lint-fix && yarn lint-deps"
}
},
"author": "Amazon Web Services",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasNodeToNodeEncryptionOptions } from '../nodeToNodeEncryption';
import { hasNodeToNodeEncryptionOptions } from '../../../../provider-utils/awscloudformation/current-backend-state/searchable-node-to-node-encryption';

describe('hasNodeToNodeEncryptionOptions', () => {
test('returns true if the search domain has NodeToNodeEncryptionOptions with value true', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { $TSContext } from '@aws-amplify/amplify-cli-core';
import { constructDefaultGlobalAmplifyInput, readRDSGlobalAmplifyInput, ImportedRDSType, constructRDSGlobalAmplifyInput } from '@aws-amplify/graphql-transformer-core';
import { ImportedRDSType } from '@aws-amplify/graphql-transformer-core';
import { constructDefaultGlobalAmplifyInput, readRDSGlobalAmplifyInput, constructRDSGlobalAmplifyInput } from '../../../../../provider-utils/awscloudformation/utils/rds-input-utils';
import * as fs from 'fs-extra';

jest.mock('fs-extra', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $TSContext } from '@aws-amplify/amplify-cli-core';
import { $TSContext, stateManager } from '@aws-amplify/amplify-cli-core';
import { getParameterStoreSecretPath } from '@aws-amplify/graphql-transformer-core';
import { getExistingConnectionSecrets } from '../../../../../provider-utils/awscloudformation/utils/rds-secrets/database-secrets';

Expand Down Expand Up @@ -37,10 +37,12 @@ describe('Test database secrets management', () => {
});

it('Returns correct path for secrets in parameter store for a database', () => {
const usernamePath = getParameterStoreSecretPath('username', mockDatabase, mockAPIName);
const appId = stateManager.getAppID();
const envName = stateManager.getCurrentEnvName();
const usernamePath = getParameterStoreSecretPath('username', mockDatabase, mockAPIName, envName, appId);
expect(usernamePath).toEqual('/amplify/fake-app-id/test/AMPLIFY_apimockapimockdatabase_username');

const passwordPath = getParameterStoreSecretPath('password', mockDatabase, mockAPIName);
const passwordPath = getParameterStoreSecretPath('password', mockDatabase, mockAPIName, envName, appId);
expect(passwordPath).toEqual('/amplify/fake-app-id/test/AMPLIFY_apimockapimockdatabase_password');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getDirectiveDefinitions = async (context: $TSContext, resourceDir:
const transformerVersion = await getTransformerVersion(context);
const transformer = await getTransformerFactory(context, resourceDir);
const transformList = transformerVersion === 2
? await transformer({ addSearchableTransformer: true, authConfig: {} })
? await transformer({ authConfig: {} })
: await transformer(true);

const transformDirectives = transformList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ const _buildProject = async (context: $TSContext, opts: TransformerProjectOption
buildParameters: opts.buildParameters,
stacks: opts.projectConfig.stacks || {},
featureFlags: new AmplifyCLIFeatureFlagAdapter(),
filepaths: {
getBackendDirPath: () => pathManager.getBackendDirPath(),
findProjectRoot: () => pathManager.findProjectRoot(),
getCurrentCloudBackendDirPath: () => pathManager.getCurrentCloudBackendDirPath(),
},
sandboxModeEnabled: opts.sandboxModeEnabled,
userDefinedSlots,
resolverConfig: opts.resolverConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ import { GraphQLTransform } from '@aws-amplify/graphql-transformer-core';
import { parseUserDefinedSlots } from './user-defined-slots';
import { AmplifyCLIFeatureFlagAdapter } from './amplify-cli-feature-flag-adapter';
import { TransformerProjectOptions } from './transformer-options-types';
import { shouldEnableNodeToNodeEncryption } from '../provider-utils/awscloudformation/current-backend-state/searchable-node-to-node-encryption';

const PROVIDER_NAME = 'awscloudformation';

type TransformerFactoryArgs = {
addSearchableTransformer: boolean;
authConfig: any;
storageConfig?: any;
adminRoles?: Array<string>;
Expand All @@ -76,6 +76,14 @@ export const getTransformerFactory = async (
const getTransformerFactoryV2 = (
resourceDir: string,
): (options: TransformerFactoryArgs) => Promise<TransformerPluginProviderV2[]> => async (options?: TransformerFactoryArgs) => {
const resourceDirParts = resourceDir.split(path.sep);
const apiName = resourceDirParts[resourceDirParts.length - 1];
const nodeToNodeEncryption = shouldEnableNodeToNodeEncryption(
apiName,
pathManager.findProjectRoot(),
pathManager.getCurrentCloudBackendDirPath(),
);

const modelTransformer = new ModelTransformerV2();
const indexTransformer = new IndexTransformerV2();
const hasOneTransformer = new HasOneTransformerV2();
Expand All @@ -97,15 +105,11 @@ const getTransformerFactoryV2 = (
new DefaultValueTransformerV2(),
authTransformer,
new MapsToTransformerV2(),
// TODO: initialize transformer plugins
new SearchableModelTransformerV2({
enableNodeToNodeEncryption: nodeToNodeEncryption,
}),
];

if (options?.addSearchableTransformer) {
const resourceDirParts = resourceDir.split(path.sep);
const apiName = resourceDirParts[resourceDirParts.length - 1];
transformerList.push(new SearchableModelTransformerV2(apiName));
}

const customTransformersConfig = await loadProject(resourceDir);
const customTransformerList = customTransformersConfig?.config?.transformers;
const customTransformers = (Array.isArray(customTransformerList) ? customTransformerList : [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type SanityCheckRules = {
* Used to determine how to create a new GraphQLTransform
*/
export type TransformerFactoryArgs = {
addSearchableTransformer: boolean;
authConfig: any;
storageConfig?: any;
adminRoles?: Array<string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ export const generateTransformerOptions = async (
warnOnAuth(directiveMap.types, docLink);
}

let searchableTransformerFlag = false;

if (directiveMap.directives.includes('searchable')) {
searchableTransformerFlag = true;
}

// construct sanityCheckRules
const ff = new AmplifyCLIFeatureFlagAdapter();
const isNewAppSyncAPI: boolean = resourcesToBeCreated.some(resource => resource.service === 'AppSync');
Expand Down Expand Up @@ -247,7 +241,6 @@ export const generateTransformerOptions = async (
projectDirectory: resourceDir,
transformersFactory: transformerListFactory,
transformersFactoryArgs: {
addSearchableTransformer: searchableTransformerFlag,
storageConfig,
authConfig,
adminRoles,
Expand Down
Loading

0 comments on commit 33a8dd6

Please sign in to comment.