Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move data schema generator to separate package #2426

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/amplify-data-schema-generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.d.ts
*.ts.map
*.js
*.js.map
lib/*
5 changes: 5 additions & 0 deletions packages/amplify-data-schema-generator/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/__mocks__/**
**/__tests__/**
src
tsconfig.json
tsconfig.tsbuildinfo
40 changes: 40 additions & 0 deletions packages/amplify-data-schema-generator/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## API Report File for "@aws-amplify/data-schema-generator"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import { Schema } from '@aws-amplify/graphql-schema-generator';
import { VpcConfig } from '@aws-amplify/graphql-transformer-interfaces';

// @public (undocumented)
export type DataSourceConfig = {
secretName: string;
identifier: string;
vpcConfig?: VpcConfig;
};

// @public (undocumented)
export const generateTypescriptDataSchema: (schema: Schema, config?: DataSourceConfig) => string;

// @public (undocumented)
export class TypescriptDataSchemaGenerator {
// (undocumented)
static generate: (config: TypescriptDataSchemaGeneratorConfig) => Promise<string>;
}

// @public (undocumented)
export type TypescriptDataSchemaGeneratorConfig = {
engine: 'mysql' | 'postgresql';
host: string;
port: number;
database: string;
username: string;
password: string;
connectionUriSecretName: string;
outputFile?: string;
};

// (No @packageDocumentation comment for this package)

```
82 changes: 82 additions & 0 deletions packages/amplify-data-schema-generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@aws-amplify/data-schema-generator",
"version": "0.1.0",
"description": "Amplify data schema generator",
"repository": {
"type": "git",
"url": "https://github.com/aws-amplify/amplify-category-api.git",
"directory": "packages/amplify-graphql-schema-generator"
},
"author": "Amazon Web Services",
"license": "Apache-2.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [
"graphql",
"schema",
"aws",
"amplify",
"generator"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"clean": "rimraf ./lib",
"test": "jest",
"extract-api": "ts-node ../../scripts/extract-api.ts"
},
"dependencies": {
"@aws-amplify/graphql-schema-generator": "0.8.2",
"@aws-amplify/graphql-transformer-interfaces": "3.6.0",
"graphql-transformer-common": "4.30.0",
"typescript": "^4.8.4"
},
"devDependencies": {
"@types/node": "^18.17.0",
"@types/pluralize": "^0.0.29"
},
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testURL": "http://localhost",
"testRegex": "(src/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"modulePathIgnorePatterns": [
"__utils__"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"collectCoverage": true,
"coverageProvider": "v8",
"coverageThreshold": {
"global": {
"branches": 76,
"functions": 74,
"lines": 82
}
},
"coverageReporters": [
"clover",
"text"
],
"moduleNameMapper": {
"^csv-parse/sync": "<rootDir>/../../node_modules/csv-parse/dist/cjs/sync.cjs"
},
"testEnvironment": "../../FixJestEnvironment.js",
"collectCoverageFrom": [
"src/**/*.ts"
],
"coveragePathIgnorePatterns": [
"/__tests__/"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { Engine, Field, Model, Schema } from '../schema-representation';
import { generateTypescriptDataSchema } from '../ts-schema-generator/generate-ts-schema';
import { DataSourceConfig } from '../ts-schema-generator/helpers';
import { TypescriptDataSchemaGenerator } from '../ts-schema-generator/ts-schema-generator';

jest.mock('../utils', () => ({
getHostVpc: jest.fn(() => {
return {
vpcId: 'abc',
securityGroupIds: ['sg0', 'sg1', 'sg2'],
subnetAvailabilityZoneConfig: [
{
subnetId: 'sb0',
availabilityZone: 'az0',
},
{
subnetId: 'sb1',
availabilityZone: 'az1',
},
{
subnetId: 'sb2',
availabilityZone: 'az2',
},
],
};
}),
}));
import { Engine, Field, Model, Schema } from '@aws-amplify/graphql-schema-generator';
import { generateTypescriptDataSchema } from '../generate-ts-schema';
import { DataSourceConfig } from '../helpers';
import { TypescriptDataSchemaGenerator } from '../ts-schema-generator';

jest.mock('@aws-amplify/graphql-schema-generator', () => {
const schemaGenerator = jest.requireActual('@aws-amplify/graphql-schema-generator');
return {
...schemaGenerator,
getHostVpc: jest.fn(() => {
return {
vpcId: 'abc',
securityGroupIds: ['sg0', 'sg1', 'sg2'],
subnetAvailabilityZoneConfig: [
{
subnetId: 'sb0',
availabilityZone: 'az0',
},
{
subnetId: 'sb1',
availabilityZone: 'az1',
},
{
subnetId: 'sb2',
availabilityZone: 'az2',
},
],
};
}),
};
});

describe('Type name conversions', () => {
it('ts schema generator should invoke generate schema', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import { Schema } from '../schema-representation';
import { Schema } from '@aws-amplify/graphql-schema-generator';
import { createImportExpression, createSchema, DataSourceConfig } from './helpers';

const file = ts.createSourceFile('schema.ts', '', ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ts from 'typescript';
import { TYPESCRIPT_DATA_SCHEMA_CONSTANTS } from 'graphql-transformer-common';
import { VpcConfig } from '@aws-amplify/graphql-transformer-interfaces';
import { DBEngineType, Field, FieldType, Model, Schema } from '../schema-representation';
import { DBEngineType, Field, FieldType, Model, Schema } from '@aws-amplify/graphql-schema-generator';

const GQL_TYPESCRIPT_DATA_SCHEMA_TYPE_MAP = {
string: 'string',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import {
DataSourceAdapter,
MySQLDataSourceAdapter,
PostgresDataSourceAdapter,
DBEngineType,
Engine,
Schema,
getHostVpc,
} from '@aws-amplify/graphql-schema-generator';
import { createHash } from 'crypto';
import { DataSourceAdapter, MySQLDataSourceAdapter, PostgresDataSourceAdapter } from '../datasource-adapter';
import { DBEngineType, Engine, Schema } from '../schema-representation';
import { getHostVpc } from '../utils';
import { generateTypescriptDataSchema } from './generate-ts-schema';

// This is the contract for the customer facing API to provide the database configuration in a typescript file.
Expand Down
13 changes: 13 additions & 0 deletions packages/amplify-data-schema-generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src/**/*.ts"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib",
"strict": false,
"composite": false,
"allowJs": true,
"moduleResolution": "node"
},
"references": [{ "path": "../amplify-graphql-transformer-core" }]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as path from 'path';
import * as fs from 'fs';
import { createNewProjectDir, deleteProjectDir, npmInstall, npmTest } from 'amplify-category-api-e2e-core';
import { DBEngineType, Engine, Field, Model, Schema, generateTypescriptDataSchema } from '@aws-amplify/graphql-schema-generator';
import { DBEngineType, Engine, Field, Model, Schema } from '@aws-amplify/graphql-schema-generator';
import { generateTypescriptDataSchema } from '@aws-amplify/data-schema-generator';

describe('validate generated typescript data schema', () => {
let projectDir: string;
Expand Down
28 changes: 0 additions & 28 deletions packages/amplify-graphql-schema-generator/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ export abstract class DataSourceAdapter {
vpcSchemaInspectorLambda: string | undefined;
}

// @public (undocumented)
export type DataSourceConfig = {
secretName: string;
identifier: string;
vpcConfig?: VpcConfig;
};

// @public (undocumented)
export type DBEngineType = 'MySQL' | 'Postgres' | 'DynamoDB';

Expand Down Expand Up @@ -163,9 +156,6 @@ export const findMatchingField: (columnName: string, taleName: string, document:
// @public (undocumented)
export const generateGraphQLSchema: (schema: Schema, existingSchemaDocument?: DocumentNode | undefined) => string;

// @public (undocumented)
export const generateTypescriptDataSchema: (schema: Schema, config?: DataSourceConfig) => string;

// @public (undocumented)
export const getHostVpc: (hostname: string, region?: string) => Promise<VpcConfig | undefined>;

Expand Down Expand Up @@ -424,24 +414,6 @@ export abstract class StringDataSourceAdapter {
protected abstract validateSchema(schema: any[]): void;
}

// @public (undocumented)
export class TypescriptDataSchemaGenerator {
// (undocumented)
static generate: (config: TypescriptDataSchemaGeneratorConfig) => Promise<string>;
}

// @public (undocumented)
export type TypescriptDataSchemaGeneratorConfig = {
engine: 'mysql' | 'postgresql';
host: string;
port: number;
database: string;
username: string;
password: string;
connectionUriSecretName: string;
outputFile?: string;
};

// (No @packageDocumentation comment for this package)

```
3 changes: 1 addition & 2 deletions packages/amplify-graphql-schema-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"mysql2": "~3.9.4",
"ora": "^4.0.3",
"pg": "~8.11.3",
"pluralize": "^8.0.0",
"typescript": "^4.8.4"
"pluralize": "^8.0.0"
},
"devDependencies": {
"@types/node": "^18.17.0",
Expand Down
1 change: 0 additions & 1 deletion packages/amplify-graphql-schema-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './utils';
export * from './schema-representation';
export * from './generate';
export * from './input';
export * from './ts-schema-generator';
Loading