This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Resources":{ | |
"LambdaResolverDataSource":{ | |
"Type":"AWS::AppSync::DataSource", | |
"Properties":{ | |
"ApiId":{ | |
"Ref":"AppSyncApiId" | |
}, | |
"Name":"LambdaResolverFunction", | |
"Type":"AWS_LAMBDA", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = async (event, context, callback) => { | |
switch(event.field) { | |
case "getTodo": | |
const todo = {"id": "1", "name": "My TODO", "description": "My first TODO"}; | |
callback(null, todo); | |
break; | |
// Add any methods that you want here. | |
default: | |
callback("Unknown field, unable to resolve" + event.field, null); | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$utils.toJson($context.result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "2017-02-28", | |
"operation": "Invoke", | |
"payload": { | |
"field": "getTodo", | |
"arguments": $utils.toJson($context.arguments) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = async (event, context, callback) => { | |
// Simple Postgres lib that supports async calls | |
const { Pool } = require('pg'); | |
const pool = new Pool(); | |
switch(event.field) { | |
case "getTodo": | |
var id = event.arguments.id; | |
const querySelect = 'SELECT * FROM todo WHERE id = $1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema { | |
query: Query | |
mutation: Mutation | |
} | |
type Query { | |
getTodo(id:ID!): Todo | |
allTodos: [Todo] | |
} |