## Installation In order to add this package to your service, run the following command: ``` npm i gj-aws-appsync ```
npm install gj-aws-appsync
npm i gj-aws-appsync
`Usage
`jsconst schema =
type Product {
id: String
name: String
}
type Extra {
id: String
product: String
}
type Query {
getHello: Hello
something: Product
product: Extra
getProduct: Extra
}
const instructions = {
name: 'DEMO-APP',
auth: {
state: 'CREATE',
existingKey: null
},
schema: {
state: 'CREATE',
defintion: schema
},
datasourceIamRoles: {
create: [
{
type: 'AWS_LAMBDA',
state: '',
name: 'testLambdaRoleName'
},
{
type: 'AMAZON_DYNAMODB',
state: '',
name: 'testDynamoDbRoleName'
}
]
},
datasources: {
create: [
{
type: 'AWS_LAMBDA',
name: inttestdatasourceLAMBDA,arn:aws:iam::12341234:role/testLambdaRoleName
lambdaArn: 'testLambdaArn',
roleArn: ,inttestdatasourceDYNAMO
roleName: 'testLambdaRoleName'
},
{
type: 'AMAZON_DYNAMODB',
name: ,arn:aws:iam::12341234:role/testDynamoDbRoleName
tableName: 'int-test-appsyncdb',
roleArn: ,inttestdatasourceLAMBDA
roleName: 'testDynamoDbRoleName'
}
]
},
resolvers: {
create: [
{
resolverType: 'AWS_LAMBDA',
type: 'Query',
field: 'getHello',
datasource: ,{
vtl: {
request:
"version": "2017-02-28",
"operation": "Invoke",
"payload": $util.toJson($ctx)
},$util.toJson($ctx.result)
response: inttestdatasourceLAMBDA
}
},
{
resolverType: 'AWS_LAMBDA',
type: 'Query',
field: 'something',
datasource: ,{
vtl: {
request:
"version": "2017-02-28",
"operation": "Invoke",
"payload": $util.toJson($ctx)
},$util.toJson($ctx.result)
response: inttestdatasourceLAMBDA
}
},
{
resolverType: 'AWS_LAMBDA',
type: 'Query',
field: 'product',
datasource: ,{
vtl: {
request:
"version": "2017-02-28",
"operation": "Invoke",
"payload": $util.toJson($ctx)
},$util.toJson($ctx.result)
response: inttestdatasourceDYNAMO
}
},
{
resolverType: 'AMAZON_DYNAMODB',
type: 'Query',
field: 'getProduct',
datasource: ,{
vtl: {
request:
"version": "2017-02-28",
"operation": "GetItem",
"key": {
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id)
},
},$util.toJson($ctx.result)
response:
}
},
]
}
}
const result = await appsync(instructions)
/*
return {
apiId: String
keyId: String
apiEndpoint: String
apiName: String
}
*/
```