Skip to content

Commit

Permalink
Merge branch 'main' into tjroach/css-and-ll
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerjroach committed Oct 4, 2023
2 parents bb6c5e7 + 7f56174 commit b318558
Show file tree
Hide file tree
Showing 37 changed files with 2,698 additions and 2,597 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ module.exports = {
'@typescript-eslint/interface-name-prefix': 'off',
'no-throw-literal': 'off',
'react/static-property-placement': 'off',
'import/no-extraneous-dependencies': 'off',
'import/no-extraneous-dependencies': ['error', {devDependencies: true}],
'spaced-comment': 'off',
'@typescript-eslint/no-array-constructor': 'off',
'prefer-rest-params': 'off',
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.1](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2023-09-26)

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

# [1.6.0](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2023-09-19)

### Features
Expand Down
6 changes: 5 additions & 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.0",
"version": "1.6.1",
"description": "",
"repository": {
"type": "git",
Expand All @@ -22,10 +22,14 @@
"clean": "rimraf ./lib"
},
"dependencies": {
"aws-sdk": "^2.1465.0",
"chalk": "^3.0.0",
"dotenv": "^8.6.0",
"execa": "^4.1.0",
"fs-extra": "^8.1.0",
"glob": "^10.3.9",
"ini": "^3.0.1",
"jest-circus": "^27.5.1",
"jest-environment-node": "^26.6.2",
"lodash": "^4.17.19",
"node-pty": "beta",
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.44.1](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2023-09-26)

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

# [2.44.0](https://github.com/aws-amplify/amplify-codegen/compare/@aws-amplify/[email protected]...@aws-amplify/[email protected]) (2023-09-19)

### Features
Expand Down
7 changes: 5 additions & 2 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.44.0",
"version": "2.44.1",
"description": "",
"repository": {
"type": "git",
Expand All @@ -22,8 +22,9 @@
"clean-e2e-resources": "ts-node ./src/cleanup-e2e-resources.ts"
},
"dependencies": {
"@aws-amplify/amplify-codegen-e2e-core": "1.6.0",
"@aws-amplify/amplify-codegen-e2e-core": "1.6.1",
"@aws-amplify/graphql-schema-test-library": "^1.1.18",
"amazon-cognito-identity-js": "^6.3.6",
"aws-amplify": "^5.3.3",
"aws-appsync": "^4.1.9",
"aws-sdk": "^2.1413.0",
Expand All @@ -33,7 +34,9 @@
"graphql-tag": "^2.10.1",
"js-yaml": "^4.0.0",
"lodash": "^4.17.19",
"node-fetch": "^3.3.2",
"uuid": "^3.4.0",
"ws": "^8.14.2",
"yargs": "^15.1.0"
},
"devDependencies": {
Expand Down
30 changes: 30 additions & 0 deletions packages/amplify-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [4.6.5](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.6.5) (2023-10-02)

### Bug Fixes

- remove unnecessary deps, including fixture dependencies ([#731](https://github.com/aws-amplify/amplify-codegen/issues/731)) ([7d71ee0](https://github.com/aws-amplify/amplify-codegen/commit/7d71ee0def32c356ef84a8cdbffe92d4aa0b0497))

## [4.6.4](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.6.4) (2023-10-02)

### Bug Fixes

- ensure posix path sep is used ([#728](https://github.com/aws-amplify/amplify-codegen/issues/728)) ([9c9e1ba](https://github.com/aws-amplify/amplify-codegen/commit/9c9e1ba4d29b8fab30598397aac434c65b143a3a))

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

### Bug Fixes

- generate multiple swift files in graphql-generator ([#718](https://github.com/aws-amplify/amplify-codegen/issues/718)) ([1e484af](https://github.com/aws-amplify/amplify-codegen/commit/1e484afe39a76ac633208698e3f780214819e44e))

## [4.6.2](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.6.2) (2023-09-25)

### Bug Fixes

- relative types path in same dir as documents ([#714](https://github.com/aws-amplify/amplify-codegen/issues/714)) ([73d3877](https://github.com/aws-amplify/amplify-codegen/commit/73d38776aaae270201aeddc87d6b97bef860c7f1))

## [4.6.1](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.6.1) (2023-09-25)

### Bug Fixes

- multiple swift file names ([#713](https://github.com/aws-amplify/amplify-codegen/issues/713)) ([a901362](https://github.com/aws-amplify/amplify-codegen/commit/a90136266944812001913b4b49972dda87750763))

# [4.6.0](https://github.com/aws-amplify/amplify-codegen/compare/[email protected]@4.6.0) (2023-09-19)

### Features
Expand Down
7 changes: 4 additions & 3 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.6.0",
"version": "4.6.5",
"description": "Amplify Code Generator",
"repository": {
"type": "git",
Expand All @@ -21,8 +21,9 @@
"extract-api": "ts-node ../../scripts/extract-api.ts"
},
"dependencies": {
"@aws-amplify/graphql-generator": "0.1.1",
"@aws-amplify/graphql-types-generator": "3.4.0",
"@aws-amplify/graphql-docs-generator": "4.2.0",
"@aws-amplify/graphql-generator": "0.1.5",
"@aws-amplify/graphql-types-generator": "3.4.3",
"@graphql-codegen/core": "2.6.6",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/amplify-codegen/src/commands/statements.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
getAppSyncAPIDetails,
readSchemaFromFile,
getAppSyncAPIInfoFromProject,
getRelativeTypesPath,
} = require('../utils');
const { generateGraphQLDocuments } = require('@aws-amplify/graphql-docs-generator');
const { generateStatements: generateStatementsHelper } = require('@aws-amplify/graphql-generator');
Expand Down Expand Up @@ -64,9 +65,6 @@ async function generateStatements(context, forceDownloadSchema, maxDepth, withou

try {
const schemaData = readSchemaFromFile(schemaPath);
const relativeTypesPath = cfg.amplifyExtension.generatedFileName
? path.relative(opsGenDirectory, cfg.amplifyExtension.generatedFileName)
: null;
const generatedOps = generateStatementsHelper({
schema: schemaData,
target: language,
Expand All @@ -75,7 +73,7 @@ async function generateStatements(context, forceDownloadSchema, maxDepth, withou
// default typenameIntrospection to true when not set
typenameIntrospection:
cfg.amplifyExtension.typenameIntrospection === undefined ? true : !!cfg.amplifyExtension.typenameIntrospection,
relativeTypesPath,
relativeTypesPath: getRelativeTypesPath(opsGenDirectory, cfg.amplifyExtension.generatedFileName),
});
if (!generatedOps) {
context.print.warning('No GraphQL statements are generated. Check if the introspection schema has GraphQL operations defined.');
Expand Down
42 changes: 21 additions & 21 deletions packages/amplify-codegen/src/commands/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');
const fs = require('fs-extra');
const Ora = require('ora');
const glob = require('glob-all');
const { Source } = require('graphql');

const constants = require('../constants');
const { loadConfig } = require('../codegen-config');
Expand Down Expand Up @@ -57,27 +58,25 @@ async function generateTypes(context, forceDownloadSchema, withoutInit = false,
const target = cfg.amplifyExtension.codeGenTarget;

const excludes = cfg.excludes.map(pattern => `!${pattern}`);
const queryFiles = glob
.sync([...includeFiles, ...excludes], {
cwd: projectPath,
absolute: true,
})
.map(queryFilePath => {
const fileContents = fs.readFileSync(queryFilePath, 'utf8');
if (
queryFilePath.endsWith('.jsx') ||
queryFilePath.endsWith('.js') ||
queryFilePath.endsWith('.tsx') ||
queryFilePath.endsWith('.ts')
) {
return extractDocumentFromJavascript(fileContents, '');
}
return fileContents;
});
if (queryFiles.length === 0) {
throw new Error('No queries found to generate types for, you may need to run \'codegen statements\' first');
const queryFilePaths = glob.sync([...includeFiles, ...excludes], {
cwd: projectPath,
absolute: true,
});
const queries = queryFilePaths.map(queryFilePath => {
const fileContents = fs.readFileSync(queryFilePath, 'utf8');
if (
queryFilePath.endsWith('.jsx') ||
queryFilePath.endsWith('.js') ||
queryFilePath.endsWith('.tsx') ||
queryFilePath.endsWith('.ts')
) {
return extractDocumentFromJavascript(fileContents, '');
}
return new Source(fileContents, queryFilePath);
});
if (queries.length === 0) {
throw new Error("No queries found to generate types for, you may need to run 'codegen statements' first");
}
const queries = queryFiles.join('\n');

const schemaPath = path.join(projectPath, cfg.schema);

Expand All @@ -94,13 +93,14 @@ async function generateTypes(context, forceDownloadSchema, withoutInit = false,
codeGenSpinner.start();
const schema = fs.readFileSync(schemaPath, 'utf8');
const introspection = path.extname(schemaPath) === '.json';

const multipleSwiftFiles = target === 'swift' && fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory();
try {
const output = await generateTypesHelper({
schema,
queries,
target,
introspection,
multipleSwiftFiles,
});
const outputs = Object.entries(output);

Expand Down
23 changes: 23 additions & 0 deletions packages/amplify-codegen/src/utils/getRelativeTypesPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');

function getRelativeTypesPath(opsGenDirectory, generatedFileName) {
if (generatedFileName) {
const relativePath = path
.relative(opsGenDirectory, generatedFileName)
// ensure posix path separators are used
.split(path.win32.sep)
.join(path.posix.sep);

// generatedFileName is in same directory as opsGenDirectory
// i.e. generatedFileName: src/graphql/API.ts, opsGenDirectory: src/graphql
if (!relativePath.startsWith('.')) {
// path.join will strip prefixed ./
return `./${relativePath}`;
}

return relativePath;
}
return null;
}

module.exports = getRelativeTypesPath;
2 changes: 2 additions & 0 deletions packages/amplify-codegen/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const switchToSDLSchema = require('./switchToSDLSchema');
const ensureIntrospectionSchema = require('./ensureIntrospectionSchema');
const { readSchemaFromFile } = require('./readSchemaFromFile');
const defaultDirectiveDefinitions = require('./defaultDirectiveDefinitions');
const getRelativeTypesPath = require('./getRelativeTypesPath');
module.exports = {
getAppSyncAPIDetails,
getFrontEndHandler,
Expand All @@ -37,4 +38,5 @@ module.exports = {
ensureIntrospectionSchema,
readSchemaFromFile,
defaultDirectiveDefinitions,
getRelativeTypesPath,
};
5 changes: 3 additions & 2 deletions packages/amplify-codegen/tests/commands/mock-fs-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const { getOutputFileName } = require('@aws-amplify/graphql-types-generator');
* Mocks existence of `schema.json` using mocks fs
* Mocks existence of `.graphqlconfig.yml` by mocking return value for loadConfig utility
*/
function setupMocks(mockFs, loadConfig, apiId, frontend, target) {
function setupMocks(mockFs, loadConfig, apiId, frontend, target, generatedFileNameOverride, extendMockFs) {
mockFs.restore();
const docsFilePath = {
javascript: 'src/graphql',
android: 'app/src/main/graphql/com/amazonaws/amplify/generated/graphql',
swift: 'graphql',
};
const generatedFileName = getOutputFileName('API', target);
const generatedFileName = generatedFileNameOverride || getOutputFileName('API', target);
const schemaFilePath = 'schema.json';
const nodeModulesPrettier = path.resolve(path.join(__dirname, '../../../../node_modules/prettier'));
const mockedFiles = {
Expand All @@ -26,6 +26,7 @@ function setupMocks(mockFs, loadConfig, apiId, frontend, target) {
lazy: true,
}),
[schemaFilePath]: mockFs.load(path.resolve(path.join(__dirname, './blog-introspection-schema.json'))),
...extendMockFs,
};
mockFs(mockedFiles);

Expand Down
27 changes: 23 additions & 4 deletions packages/amplify-codegen/tests/commands/statements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ const fs = require('fs-extra');

const { loadConfig } = require('../../src/codegen-config');
const generateStatements = require('../../src/commands/statements');
const { generateStatements: generateStatementsHelper } = require('@aws-amplify/graphql-generator');
const constants = require('../../src/constants');
const { ensureIntrospectionSchema, getFrontEndHandler, getAppSyncAPIDetails, readSchemaFromFile } = require('../../src/utils');
const {
ensureIntrospectionSchema,
getFrontEndHandler,
getAppSyncAPIDetails,
readSchemaFromFile,
getRelativeTypesPath,
} = require('../../src/utils');

const MOCK_CONTEXT = {
print: {
Expand All @@ -16,6 +23,7 @@ const MOCK_CONTEXT = {
},
};

jest.mock('@aws-amplify/graphql-generator');
jest.mock('../../src/codegen-config');
jest.mock('../../src/utils');
jest.mock('fs-extra');
Expand Down Expand Up @@ -67,21 +75,32 @@ describe('command - statements', () => {
MOCK_CONTEXT.amplify.getEnvInfo.mockReturnValue({ projectPath: MOCK_PROJECT_ROOT });
getAppSyncAPIDetails.mockReturnValue(MOCK_APIS);
readSchemaFromFile.mockReturnValue(MOCK_SCHEMA);
generateStatementsHelper.mockReturnValue({
'queries.js': 'queries',
});
});

it('should generate statements', async () => {
const forceDownload = false;
const relativePath = './relative_path';
getRelativeTypesPath.mockReturnValueOnce(relativePath);
await generateStatements(MOCK_CONTEXT, forceDownload);
expect(getFrontEndHandler).toHaveBeenCalledWith(MOCK_CONTEXT);
expect(loadConfig).toHaveBeenCalledWith(MOCK_CONTEXT, false);
expect(getRelativeTypesPath).toHaveBeenCalledWith('MOCK_PROJECT_ROOT/MOCK_STATEMENTS_PATH', 'API.TS');
expect(generateStatementsHelper).toHaveBeenCalledWith({
relativeTypesPath: relativePath,
schema: MOCK_SCHEMA,
target: MOCK_TARGET_LANGUAGE,
typenameIntrospection: true,
useExternalFragmentForS3Object: false,
});
});

it('should generate graphql statements for non JS projects', async () => {
getFrontEndHandler.mockReturnValue('ios');
loadConfig.mockReturnValue({
getProjects: jest.fn().mockReturnValue([
{ ...MOCK_PROJECT, ...{ amplifyExtension: { codeGenTarget: 'javascript' }} }
]),
getProjects: jest.fn().mockReturnValue([{ ...MOCK_PROJECT, ...{ amplifyExtension: { codeGenTarget: 'javascript' } } }]),
});
const forceDownload = false;
await generateStatements(MOCK_CONTEXT, forceDownload);
Expand Down
16 changes: 16 additions & 0 deletions packages/amplify-codegen/tests/commands/types-mock-fs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ describe('command - types (mock fs)', () => {
});
});

it('should generate multiple swift files if generatedFileName is a dir', async () => {
const generatedFileName = 'api';
setupMocks(mockFs, loadConfig, MOCK_API_ID, 'swift', 'swift', generatedFileName, { [generatedFileName]: {} });

await generateStatements(MOCK_CONTEXT, false);
await generateTypes(MOCK_CONTEXT, false);

expect(fs.existsSync(generatedFileName)).toBeTruthy();
expect(fs.readdirSync(generatedFileName)).toEqual([
'Types.graphql.swift',
'mutations.graphql.swift',
'queries.graphql.swift',
'subscriptions.graphql.swift',
]);
});

it('should not generate types when target is javascript', async () => {
const generatedFileName = setupMocks(mockFs, loadConfig, MOCK_API_ID, 'javascript', 'javascript');

Expand Down
Loading

0 comments on commit b318558

Please sign in to comment.