-
Notifications
You must be signed in to change notification settings - Fork 4k
/
integ.graphql-s3.ts
54 lines (46 loc) · 1.83 KB
/
integ.graphql-s3.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
import * as path from 'path';
import * as db from '@aws-cdk/aws-dynamodb';
import * as assets from '@aws-cdk/aws-s3-assets';
import * as cdk from '@aws-cdk/core';
import * as appsync from '../lib';
/*
* Creates an Appsync GraphQL API with schema definition through
* s3 location.
*
* Stack verification steps:
* Deploy app and check if schema is defined.
*
* da2-z3xi4w55trgmxpzley2t7bfefe https://vymliuqndveudjq352yk4cuvg4.appsync-api.us-east-1.amazonaws.com/graphql
*
* -- cdk deploy --app 'node integ.graphql-s3.js' -- start --
* -- aws appsync list-graphql-apis -- obtain api id && endpoint --
* -- aws appsync list-api-keys --api-id [API ID] -- obtain api key --
* -- bash verify.integ.graphql-s3.sh [APIKEY] [ENDPOINT] -- return with "getTests" --
* -- cdk destroy --app 'node integ.graphql-s3.js' -- clean --
*/
const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-appsync-integ');
const asset = new assets.Asset(stack, 'SampleAsset', {
path: path.join(__dirname, 'appsync.test.graphql'),
});
const api = new appsync.GraphQLApi(stack, 'Api', {
name: 'integ-test-s3',
schemaDefinition: appsync.SchemaDefinition.S3,
schemaDefinitionFile: asset.s3ObjectUrl,
});
const testTable = new db.Table(stack, 'TestTable', {
billingMode: db.BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: 'id',
type: db.AttributeType.STRING,
},
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const testDS = api.addDynamoDbDataSource('testDataSource', 'Table for Tests"', testTable);
testDS.createResolver({
typeName: 'Query',
fieldName: 'getTests',
requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});
app.synth();