https://github.com/bearchit/appsync-handler
AWS AppSync Resolver Handler Library
https://github.com/bearchit/appsync-handler
appsync aws go graphql handler lambda resolver
Last synced: about 1 month ago
JSON representation
AWS AppSync Resolver Handler Library
- Host: GitHub
- URL: https://github.com/bearchit/appsync-handler
- Owner: bearchit
- License: mit
- Created: 2019-05-05T11:35:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-07T08:41:50.000Z (about 7 years ago)
- Last Synced: 2023-03-24T03:38:22.221Z (about 3 years ago)
- Topics: appsync, aws, go, graphql, handler, lambda, resolver
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AWS AppsSync Handler
## Resolver signatures
```text
func()
func() error
func(in) error
func() (out), error)
func(in) (out, error)
func(context.Context) error
func(context.Context, out) error
func(context.Context) (out, error)
func(context.Context, in) (out, error)
```
"in", "out" are types compatiable with the [encoding/json](https://golang.org/pkg/encoding/json).
## Example
### AppSync Request Mapping Template
```vtl
{
"version": "2017-02-28",
"operation": "Invoke",
#set($args = $ctx.args.input)
$utils.qr($args.put("userID", $ctx.identity.sub))
"payload": {
"resolve": "query.posts",
"arguments": $utils.toJson($args)
}
}
```
### Lambda function
```go
package main
import (
"context"
"github.com/bearchit/appsync-handler"
)
type postsInput struct {
UserID string `json:"userID"`
Limit uint64 `json:"limit"`
NextToken string `json:"nextToken"`
}
type post struct {
ID string `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
}
func main() {
h := appsync.NewHandler()
h.AddResolver("query.post", func(ctx context.Context, input *postsInput) ([]*post, error) {
// You can access `arguments` in the payload with struct `postInput`
log.Println(input.UserID)
log.Println(input.Limit)
log.Println(input.NextToken)
return []*post{
{
ID: "1",
Title: "post #1",
Content: "A content of post #1",
},
{
ID: "2",
Title: "post #2",
Content: "A content of post #2",
},
}, nil
})
lambda.Start(h.Handle)
}
```