-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathgraphqlapi-base.ts
189 lines (171 loc) · 5.12 KB
/
graphqlapi-base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { ITable } from '@aws-cdk/aws-dynamodb';
import { IFunction } from '@aws-cdk/aws-lambda';
import { CfnResource, IResource, Resource } from '@aws-cdk/core';
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource } from './data-source';
/**
* Optional configuration for data sources
*/
export interface DataSourceOptions {
/**
* The name of the data source
*
* @default - '<DataSourceType>CDKDefault'
*/
readonly name?: string;
/**
* The description of the data source
*
* @default - undefined
*/
readonly description?: string;
}
/**
* Interface for GraphQL
*/
export interface IGraphQLApi extends IResource {
/**
* an unique AWS AppSync GraphQL API identifier
* i.e. 'lxz775lwdrgcndgz3nurvac7oa'
*
* @attribute
*/
readonly apiId: string;
/**
* the ARN of the API
*
* @attribute
*/
readonly arn: string;
/**
* add a new dummy data source to this API. Useful for pipeline resolvers
* and for backend changes that don't require a data source.
*
* @param options The optional configuration for this data source
* @default name - 'NoneCDKDefault'
* description - undefined
*/
addNoneDataSource(options?: DataSourceOptions): NoneDataSource;
/**
* add a new DynamoDB data source to this API
*
* @param table The DynamoDB table backing this data source
* @param options The optional configuration for this data source
* @default name - 'DynamoDbCDKDefault'
* description - undefined
*/
addDynamoDbDataSource(table: ITable, options?: DataSourceOptions): DynamoDbDataSource;
/**
* add a new http data source to this API
*
* @param endpoint The http endpoint
* @param options The optional configuration for this data source
* @default name - 'HttpCDKDefault'
* description - undefined
*/
addHttpDataSource(endpoint: string, options?: DataSourceOptions): HttpDataSource;
/**
* add a new Lambda data source to this API
*
* @param lambdaFunction The Lambda function to call to interact with this data source
* @param options The optional configuration for this data source
* @default name - 'LambdaCDKDefault'
* description - undefined
*/
addLambdaDataSource(lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource;
/**
* Add schema dependency if not imported
*
* @param construct the dependee
*/
addSchemaDependency(construct: CfnResource): boolean;
}
/**
* Base Class for GraphQL API
*/
export abstract class GraphQLApiBase extends Resource implements IGraphQLApi {
/**
* an unique AWS AppSync GraphQL API identifier
* i.e. 'lxz775lwdrgcndgz3nurvac7oa'
*/
public abstract readonly apiId: string;
/**
* the ARN of the API
*/
public abstract readonly arn: string;
/**
* add a new none data source to this API. Useful for pipeline resolvers
* and for backend changes that don't require a data source.
*
* @param options The optional configuration for this data source
* @default name - 'NoneCDKDefault'
* description - undefined
*/
public addNoneDataSource(options?: DataSourceOptions): NoneDataSource {
const name = options?.name ?? 'NoneCDKDefault';
return new NoneDataSource(this, name, {
api: this,
name: name,
description: options?.description,
});
}
/**
* add a new DynamoDB data source to this API
*
* @param table The DynamoDB table backing this data source
* @param options The optional configuration for this data source
* @default name - 'TableCDKDefault'
* description - undefined
*/
public addDynamoDbDataSource(table: ITable, options?: DataSourceOptions): DynamoDbDataSource {
const name = options?.name ?? 'TableCDKDefault';
return new DynamoDbDataSource(this, name, {
api: this,
table,
name,
description: options?.description,
});
}
/**
* add a new http data source to this API
*
* @param endpoint The http endpoint
* @param options The optional configuration for this data source
* @default name - 'HttpCDKDefault'
* description - undefined
*/
public addHttpDataSource(endpoint: string, options?: DataSourceOptions): HttpDataSource {
const name = options?.name ?? 'HttpCDKDefault';
return new HttpDataSource(this, name, {
api: this,
endpoint,
name,
description: options?.description,
});
}
/**
* add a new Lambda data source to this API
*
* @param lambdaFunction The Lambda function to call to interact with this data source
* @param options The optional configuration for this data source
* @default name - 'LambdaCDKDefault'
* description - undefined
*/
public addLambdaDataSource(lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource {
const name = options?.name ?? 'LambdaCDKDefault';
return new LambdaDataSource(this, name, {
api: this,
lambdaFunction,
name,
description: options?.description,
});
}
/**
* Add schema dependency if not imported
*
* @param construct the dependee
*/
public addSchemaDependency(construct: CfnResource): boolean {
construct;
return false;
}
}