appsyncgraphql

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 12 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AWSDate

func AWSDate(now time.Time, timezoneOffset ...float64) (string, error)

func AWSDateTime

func AWSDateTime(now time.Time, timezoneOffset ...float64) (string, error)

func AWSTime

func AWSTime(now time.Time, timezoneOffset ...float64) (string, error)

func AWSTimestamp

func AWSTimestamp(now time.Time) int64

AWSTimestamp floors seconds since the Unix epoch, including negative instants. Scalar helpers take an explicit clock value to keep applications deterministic.

func MakeID

func MakeID() (string, error)

MakeID returns a cryptographically random RFC 4122 version 4 identifier.

Types

type BatchOptions

type BatchOptions struct {
	Individual   bool
	ThrowOnError bool
}

BatchOptions defaults to aggregate execution, as in TypeScript. Individual selects sequential per-event execution; failures become null unless ThrowOnError.

type Event

type Event = map[string]any

Event retains unknown fields in a JSON-decoded AppSync event.

type ExceptionHandler

type ExceptionHandler func(context.Context, error) (any, error)

type Handler

type Handler func(ctx context.Context, input, event any) (any, error)

Handler receives arguments and the complete event. Aggregate batch handlers receive the complete event slice in both positions. Context is never replaced.

type InvalidBatchResponseException

type InvalidBatchResponseException struct {
	Message string
	Cause   error
}

InvalidBatchResponseException reports a non-array aggregate result.

func (*InvalidBatchResponseException) Error

func (*InvalidBatchResponseException) ErrorName

func (e *InvalidBatchResponseException) ErrorName() string

func (*InvalidBatchResponseException) Unwrap

type NamedError

type NamedError struct {
	Name, Message string
	Cause         error
}

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 Options

type Options struct {
	// Diagnostic runs outside registry locks and may be called concurrently.
	// Registration uses context.Background; invocation diagnostics retain context.
	Diagnostic func(ctx context.Context, level, message string, err error)
}

type Resolver

type Resolver struct{ *Router }

func New

func New(options Options) *Resolver

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, input any) (any, error)

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

type ResolverNotFoundException struct {
	Message string
	Cause   error
}

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 NewRouter

func NewRouter(options Options) *Router

func (*Router) IncludeRouter

func (r *Router) IncludeRouter(routers ...*Router)

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.

func (*Router) OnMutation

func (r *Router) OnMutation(field string, handler Handler)

func (*Router) OnQuery

func (r *Router) OnQuery(field string, handler Handler)

func (*Router) OnResolver

func (r *Router) OnResolver(typeName, field string, handler Handler)

type TypeError

type TypeError struct{ Message string }

TypeError preserves the reference's empty-batch error name in the Lambda SDK.

func (*TypeError) Error

func (e *TypeError) Error() string

func (*TypeError) ErrorName

func (e *TypeError) ErrorName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL