Documentation
¶
Overview ¶
Package appsyncgraphql routes AWS Lambda AppSync GraphQL invocations.
New constructs a Resolver. Register query, mutation or type/field handlers through Router.OnQuery, Router.OnMutation and Router.OnResolver, then call Resolver.Resolve with decoded single or batch events.
Batch and errors ¶
BatchOptions defaults to aggregate handling; individual mode processes events sequentially and can control whether failures propagate. Handler arguments and event data are passed through without copying. Configure exception handlers with Router.OnException and use the scalar helpers for AppSync-specific values.
The application owns the GraphQL schema and Lambda integration. This resolver does not execute arbitrary GraphQL documents or provision an AppSync API.
For usage and compatibility details, see the user guide.
Index ¶
- func AWSDate(now time.Time, timezoneOffset ...float64) (string, error)
- func AWSDateTime(now time.Time, timezoneOffset ...float64) (string, error)
- func AWSTime(now time.Time, timezoneOffset ...float64) (string, error)
- func AWSTimestamp(now time.Time) int64
- func MakeID() (string, error)
- type BatchOptions
- type Event
- type ExceptionHandler
- type Handler
- type InvalidBatchResponseException
- type NamedError
- type Options
- type Resolver
- type ResolverNotFoundException
- type Router
- func (r *Router) IncludeRouter(routers ...*Router)
- func (r *Router) OnBatchMutation(field string, handler Handler, options ...BatchOptions)
- func (r *Router) OnBatchQuery(field string, handler Handler, options ...BatchOptions)
- func (r *Router) OnBatchResolver(typeName, field string, handler Handler, options ...BatchOptions)
- func (r *Router) OnException(names []string, handler ExceptionHandler)
- func (r *Router) OnMutation(field string, handler Handler)
- func (r *Router) OnQuery(field string, handler Handler)
- func (r *Router) OnResolver(typeName, field string, handler Handler)
- type TypeError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AWSTimestamp ¶
AWSTimestamp floors seconds since the Unix epoch, including negative instants. Scalar helpers take an explicit clock value to keep applications deterministic.
Types ¶
type BatchOptions ¶
BatchOptions defaults to aggregate execution, as in TypeScript. Individual selects sequential per-event execution; failures become null unless ThrowOnError.
type Handler ¶
Handler receives arguments and the complete event. Aggregate batch handlers receive the complete event slice in both positions. Context is never replaced.
type InvalidBatchResponseException ¶
InvalidBatchResponseException reports a non-array aggregate result.
func (*InvalidBatchResponseException) Error ¶
func (e *InvalidBatchResponseException) Error() string
func (*InvalidBatchResponseException) ErrorName ¶
func (e *InvalidBatchResponseException) ErrorName() string
func (*InvalidBatchResponseException) Unwrap ¶
func (e *InvalidBatchResponseException) Unwrap() error
type NamedError ¶
NamedError supplies the reference error name without coupling to another utility.
func (*NamedError) Error ¶
func (e *NamedError) Error() string
func (*NamedError) ErrorName ¶
func (e *NamedError) ErrorName() string
func (*NamedError) Unwrap ¶
func (e *NamedError) Unwrap() error
type Resolver ¶
type Resolver struct{ *Router }
func (*Resolver) Resolve ¶
Resolve accepts decoded JSON events or batches. Invalid input returns nil after a warning. Handler errors become response envelopes except the two framework exceptions, which propagate to Lambda. Events are passed through without copying.
Example ¶
package main
import (
"context"
"fmt"
"github.com/rambow-cloud/powertools-lambda-go/eventhandler/appsyncgraphql"
)
func main() {
app := appsyncgraphql.New(appsyncgraphql.Options{})
app.OnQuery("order", func(_ context.Context, input, _ any) (any, error) {
return input.(map[string]any)["id"], nil
})
event := map[string]any{
"arguments": map[string]any{"id": "order-123"},
"identity": nil, "source": nil, "prev": nil, "stash": map[string]any{},
"request": map[string]any{"headers": map[string]any{}, "domainName": nil},
"info": map[string]any{"parentTypeName": "Query", "fieldName": "order",
"variables": map[string]any{}},
}
value, err := app.Resolve(context.Background(), event)
fmt.Println(value, err)
}
Output: order-123 <nil>
type ResolverNotFoundException ¶
ResolverNotFoundException bypasses registered exception handlers. Its concrete type name also preserves errorType in the Go Lambda Runtime API response.
func (*ResolverNotFoundException) Error ¶
func (e *ResolverNotFoundException) Error() string
func (*ResolverNotFoundException) ErrorName ¶
func (e *ResolverNotFoundException) ErrorName() string
func (*ResolverNotFoundException) Unwrap ¶
func (e *ResolverNotFoundException) Unwrap() error
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router owns ordered registries. Configure routes before serving requests. Concurrent lookups and registration are safe; inclusion copies registrations.
func (*Router) IncludeRouter ¶
IncludeRouter merges in order, replacing collisions without sharing registries.
func (*Router) OnBatchMutation ¶
func (r *Router) OnBatchMutation(field string, handler Handler, options ...BatchOptions)
func (*Router) OnBatchQuery ¶
func (r *Router) OnBatchQuery(field string, handler Handler, options ...BatchOptions)
func (*Router) OnBatchResolver ¶
func (r *Router) OnBatchResolver(typeName, field string, handler Handler, options ...BatchOptions)
func (*Router) OnException ¶
func (r *Router) OnException(names []string, handler ExceptionHandler)
OnException registers exact error names, not inheritance or predicate matching.