Skip to content

Commit 8a3a132

Browse files
committed
Update README
1 parent 3ed4c1f commit 8a3a132

File tree

13 files changed

+960
-66
lines changed

13 files changed

+960
-66
lines changed

.github/README.md

Lines changed: 455 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 439 additions & 5 deletions
Large diffs are not rendered by default.

assets/images/db.png

78 KB
Loading

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare module 'aws-quick-api-config';
1+
declare module 'aws-dynasync';

src/api/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Construct } from 'constructs';
22
import { AppSyncSchema } from './schema';
33
import { getName, validateTable } from '../util';
44
import { DbTable } from '../db/table';
5-
import { SchemaTable } from '../types';
5+
import { SchemaTable, GraphQlTypeList } from '../types';
66
import {
77
GraphqlApi,
88
ISchema,
@@ -11,12 +11,11 @@ import {
1111
UserPoolConfig
1212
} from 'aws-cdk-lib/aws-appsync';
1313
import { IUserPool } from 'aws-cdk-lib/aws-cognito';
14-
import { IntermediateParams } from './schema-alpha';
1514

1615
export interface AppSyncStackProps {
1716
config: UserPoolConfig
1817
tables: (DbTable | SchemaTable)[]
19-
schemaTypes?: IntermediateParams
18+
schemaTypes?: GraphQlTypeList
2019
}
2120

2221
export class AppSyncStack {

src/api/schema-alpha.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,12 @@
1-
import { IGraphqlApi, ISchemaConfig, Resolver } from "aws-cdk-lib/aws-appsync";
1+
import { IGraphqlApi, ISchemaConfig } from "aws-cdk-lib/aws-appsync";
22
import {
33
GraphqlApi as GraphqlApiAlpha,
44
Field,
55
IIntermediateType,
66
ObjectType,
77
ResolvableField,
8-
Directive,
9-
InterfaceType,
10-
IField
118
} from "@aws-cdk/aws-appsync-alpha";
129
import { Lazy } from "aws-cdk-lib";
13-
import { SchemaObject } from "../types";
14-
15-
export interface IntermediateTypes {
16-
[name:string]: IIntermediateType
17-
}
18-
19-
export type IntermediateType = 'type' | 'input' | 'interface' | 'union' | 'enum';
20-
21-
export interface IntermediateParams {
22-
types?: IntermediateTypeList
23-
interfaces?: IntermediateTypeList
24-
inputs?: IntermediateTypeList
25-
unions?: {[name:string]: (string | IIntermediateType)[]}
26-
enums?: {[name:string]: string[]}
27-
}
28-
29-
export interface SchemaFields {
30-
[name:string]: IField
31-
}
32-
33-
export interface IntermediateTypeBase {
34-
directives?: Directive[]
35-
interfaceTypes?: InterfaceType[]
36-
intermediateType?: IIntermediateType
37-
resolvers?: Resolver[]
38-
}
39-
40-
export interface IntermediateTypeProps extends IntermediateTypeBase {
41-
definition: SchemaObject
42-
}
43-
44-
export interface IntermediateTypeOptions extends IntermediateTypeBase {
45-
definition: SchemaFields
46-
}
47-
48-
export interface IntermediateTypeList {
49-
[name:string]: IntermediateTypeProps | SchemaObject
50-
}
5110

5211
/**
5312
* Class based on aws-appsync alpha Schema class,

src/api/schema.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import {
55
} from 'aws-cdk-lib/aws-appsync';
66
import { DbTable } from '../db/table';
77
import {
8-
SchemaAlpha,
9-
IntermediateParams,
8+
SchemaAlpha
9+
} from './schema-alpha';
10+
import {
11+
SchemaObject,
12+
GraphQlTypeList,
1013
IntermediateType,
1114
IntermediateTypeProps,
1215
IntermediateTypes,
1316
SchemaFields
14-
} from './schema-alpha';
15-
import { SchemaObject } from '../types';
17+
} from '../types';
1618
import {
1719
GraphqlType,
1820
BaseTypeOptions,
@@ -39,7 +41,7 @@ export class AppSyncSchema implements ISchema {
3941
protected customTypes:string[] = []
4042
protected types:IntermediateTypes = {}
4143

42-
constructor(types?:IntermediateParams) {
44+
constructor(types?:GraphQlTypeList) {
4345
if (types && Object.keys(types).length) this.initTypes(types);
4446
}
4547

@@ -209,7 +211,7 @@ export class AppSyncSchema implements ISchema {
209211
}
210212
}
211213

212-
initTypes(types:IntermediateParams = {}) {
214+
initTypes(types:GraphQlTypeList = {}) {
213215
for (let intermediateType in types) {
214216
if (types.hasOwnProperty(intermediateType)) {
215217
const keys = Object.keys(types[intermediateType]);

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export class Dynasync extends Resource {
1515
tables:[],
1616
types: {}
1717
}
18+
19+
public static init(scope:Construct, id: string, props?:DynasyncProps): Dynasync {
20+
return new Dynasync(scope,id,props);
21+
}
22+
1823
constructor(
1924
protected scope: Construct,
2025
protected id: string,
@@ -28,11 +33,14 @@ export class Dynasync extends Resource {
2833
if (!existsSync($props.configFile)) throw new Error(`Config file ${$props.configFile} does not exist`);
2934
if (!/json/.test(extname($props.configFile))) throw new Error(`File at ${$props.configFile} is not JSON file`);
3035
}
31-
const configFilePath = $props.configFile || join(process.cwd(), 'tables.json');
36+
const configFilePath = $props.configFile || join(process.cwd(), 'dynasync.json');
3237
if (existsSync(configFilePath)) {
3338
this.$config = JSON.parse(readFileSync(configFilePath).toString());
3439
}
3540
const properties = this.props;
41+
if (!properties.tables?.length) {
42+
throw new Error("No tables provided. Cannot build API and Database without tables. Please configure parameters or provide 'dynasync.json' config file");
43+
}
3644
const userPool = properties.userPool || new UserPool(scope, `${id}UserPool`);
3745
this.appsync = new AppSyncStack(scope, `${id}AppSyncStack`, {
3846
config: {

src/types.ts

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { SchemaGlobalIndex } from "./key/global"
66
import { SchemaLocalIndex } from "./key/local"
77
import { ResourceProps } from "aws-cdk-lib"
88
import { IUserPool } from "aws-cdk-lib/aws-cognito"
9-
import {
10-
IntermediateParams
11-
} from './api/schema-alpha';
129
import { DbTable } from "./db/table"
10+
import { Directive, IField, IIntermediateType, InterfaceType } from "@aws-cdk/aws-appsync-alpha"
11+
import { Resolver } from "aws-cdk-lib/aws-appsync"
12+
1313
export interface DynasyncProps extends ResourceProps {
1414
userPool?: IUserPool
1515
tables?: (DbTable | SchemaTable)[]
1616
configFile?: string
17-
types?: IntermediateParams
17+
types?: GraphQlTypeList
1818
userPoolRegex?: string
1919
userPoolDeny?: boolean
2020
}
@@ -63,6 +63,14 @@ export interface SchemaGlobal {
6363
capacity?: Capacity
6464
}
6565

66+
export interface GraphQlTypeList {
67+
types?: IntermediateTypeList
68+
interfaces?: IntermediateTypeList
69+
inputs?: IntermediateTypeList
70+
unions?: {[name:string]: (string | IIntermediateType)[]}
71+
enums?: {[name:string]: string[]}
72+
}
73+
6674
export interface SchemaLocal {
6775
sortKey: string | KeyInstance
6876
include?: string[]
@@ -95,3 +103,32 @@ export type SchemaObject = Record<string, string>
95103
export type GraphType = 'id' | 'string' | 'int' | 'float' | 'boolean' |
96104
'awsDate' | 'awsTime' | 'awsDateTime' | 'awsTimestamp' | 'awsEmail' |
97105
'awsJson' | 'awsUrl' | 'awsPhone' | 'awsIpAddress' | 'intermediate'
106+
107+
export interface IntermediateTypes {
108+
[name:string]: IIntermediateType
109+
}
110+
111+
export type IntermediateType = 'type' | 'input' | 'interface' | 'union' | 'enum';
112+
113+
export interface SchemaFields {
114+
[name:string]: IField
115+
}
116+
117+
export interface IntermediateTypeBase {
118+
directives?: Directive[]
119+
interfaceTypes?: InterfaceType[]
120+
intermediateType?: IIntermediateType
121+
resolvers?: Resolver[]
122+
}
123+
124+
export interface IntermediateTypeProps extends IntermediateTypeBase {
125+
definition: SchemaObject
126+
}
127+
128+
export interface IntermediateTypeOptions extends IntermediateTypeBase {
129+
definition: SchemaFields
130+
}
131+
132+
export interface IntermediateTypeList {
133+
[name:string]: IntermediateTypeProps | SchemaObject
134+
}

test/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from "path";
22

3-
export const pathToJson = join(__dirname, 'tables.json');
3+
export const pathToJson = join(__dirname, 'dynasync.json');
44

55
export const passedTypes = {
66
types: {
File renamed without changes.

test/unit/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Dynasync } from '../../src';
33
import { App, Stack } from 'aws-cdk-lib';
44
import { join } from 'path';
55
import { UserPool } from 'aws-cdk-lib/aws-cognito';
6-
import {tables} from '../tables.json';
6+
import {tables} from '../dynasync.json';
77
import { writeFileSync } from 'fs';
8-
import { SchemaTable, SchemaTableInstance } from '../../src/types';
8+
import { SchemaTable } from '../../src/types';
99
import { definition } from '../schema';
1010
import { pathToJson, passedTypes } from '../data';
1111
import { DbTable } from '../../src/db/table';

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"target":"ES2018",
44
"module": "commonjs",
5-
"lib": ["es2016", "es2017.object", "es2017.string"],
5+
"lib": ["es2018"],
66
"declaration": true,
77
"outDir": "lib",
88
"declarationDir": "lib/types",

0 commit comments

Comments
 (0)