Skip to content

Instantly share code, notes, and snippets.

@liamross
Created July 14, 2021 18:07
Show Gist options
  • Save liamross/2fad1b93614eefbba09e9a20f7639fc5 to your computer and use it in GitHub Desktop.
Save liamross/2fad1b93614eefbba09e9a20f7639fc5 to your computer and use it in GitHub Desktop.
Types for AWS AppSync event sent to Lambda resolvers.
package util
// ResolverType is one of "Query", "Mutation", or "Subscription".
type ResolverType string
const (
// QueryResolver is the resolver type for query operations.
QueryResolver ResolverType = "Query"
// MutationResolver is the resolver type for mutation operations.
MutationResolver ResolverType = "Mutation"
// SubscriptionResolver is the resolver type for subscription operations.
SubscriptionResolver ResolverType = "Subscription"
)
// AuthStrategy is one of "ALLOW" or "DENY"
type AuthStrategy string
const (
// AllowAuth is allowing by default.
AllowAuth AuthStrategy = "ALLOW"
// DenyAuth is denying by default.
DenyAuth AuthStrategy = "DENY"
)
// For full reference expand to see full JSON here. Some items are left out:
// https://github.com/aws/aws-lambda-go/issues/344#issue-767176415
type (
// ResolverEvent is the object sent from AWS to the resolver.
ResolverEvent struct {
// Arguments are whatever is passed into the resolver as an
// argument. This will be a JSON object with key as the field
// and value as the value.
Arguments map[string]interface{} `json:"arguments"`
Info ResolverInfo `json:"info"`
Identity *ResolverIdentity `json:"identity"`
}
// ResolverInfo contains information about the request.
ResolverInfo struct {
// ParentTypeName is "Query", "Mutation", or "Subscription".
ParentTypeName ResolverType `json:"parentTypeName"`
// FieldName is the resolver field within the parent type.
FieldName string `json:"fieldName"`
// SelectionSetList is a list of the requested fields to be
// returned from the resolver.
SelectionSetList []string `json:"selectionSetList"`
}
// ResolverIdentity contains identity information.
ResolverIdentity struct {
Claims IdentityClaims `json:"claims"`
DefaultAuthStrategy AuthStrategy `json:"defaultAuthStrategy"`
Groups *[]string `json:"groups"`
Issuer string `json:"issuer"`
SourceIP []string `json:"sourceIp"`
Sub string `json:"sub"`
Username string `json:"username"`
}
// IdentityClaims contains properties of the identity.
IdentityClaims struct {
Aud string `json:"aud"`
AuthTime int64 `json:"auth_time"`
CognitoUsername string `json:"cognito:username"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
EventID string `json:"event_id"`
Exp int64 `json:"exp"`
IAT int64 `json:"iat"`
ISS string `json:"iss"`
PhoneNumber string `json:"phone_number"`
PhoneNumberVerified bool `json:"phone_number_verified"`
Sub string `json:"sub"`
TokenUse string `json:"token_use"`
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment