|
61 | 61 | pub source_ip: Vec<String>,
|
62 | 62 | #[serde(default)]
|
63 | 63 | pub default_auth_strategy: Option<String>,
|
| 64 | + #[serde(default)] |
| 65 | + pub groups: Option<Vec<String>>, |
64 | 66 | }
|
65 | 67 |
|
66 | 68 | pub type AppSyncOperation = String;
|
@@ -117,6 +119,88 @@ where
|
117 | 119 | pub ttl_override: Option<i64>,
|
118 | 120 | }
|
119 | 121 |
|
| 122 | +/// `AppSyncResolverEvent` represents the default payload structure sent by AWS AppSync |
| 123 | +/// when using **Direct Lambda Resolvers** (i.e., when both request and response mapping |
| 124 | +/// templates are disabled). |
| 125 | +/// |
| 126 | +/// This structure includes the full AppSync **Context object**, as described in the |
| 127 | +/// [AppSync Direct Lambda resolver reference](https://docs.aws.amazon.com/appsync/latest/devguide/direct-lambda-reference.html). |
| 128 | +/// |
| 129 | +/// It is recommended when working without VTL templates and relying on the standard |
| 130 | +/// AppSync-to-Lambda event format. |
| 131 | +/// |
| 132 | +/// See also: |
| 133 | +/// - [AppSync resolver mapping template context reference](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html) |
| 134 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 135 | +pub struct AppSyncResolverEvent<TArguments = Option<Value>, TSource = Option<Value>> { |
| 136 | + pub arguments: TArguments, |
| 137 | + pub identity: Option<AppSyncIdentity>, |
| 138 | + pub source: TSource, |
| 139 | + pub request: AppSyncRequest, |
| 140 | + pub info: AppSyncInfo, |
| 141 | + #[serde(default)] |
| 142 | + pub prev: Option<AppSyncPrevResult>, |
| 143 | + pub stash: HashMap<String, Value>, |
| 144 | +} |
| 145 | + |
| 146 | +/// `AppSyncRequest` contains request-related metadata for a resolver invocation, |
| 147 | +/// including client-sent headers and optional custom domain name. |
| 148 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 149 | +#[serde(rename_all = "camelCase")] |
| 150 | +pub struct AppSyncRequest { |
| 151 | + #[serde(default)] |
| 152 | + pub headers: HashMap<String, Option<String>>, |
| 153 | + #[serde(default)] |
| 154 | + pub domain_name: Option<String>, |
| 155 | +} |
| 156 | + |
| 157 | +/// `AppSyncInfo` contains metadata about the current GraphQL field being resolved. |
| 158 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 159 | +#[serde(rename_all = "camelCase")] |
| 160 | +pub struct AppSyncInfo { |
| 161 | + #[serde(default)] |
| 162 | + pub selection_set_list: Vec<String>, |
| 163 | + #[serde(rename = "selectionSetGraphQL")] |
| 164 | + pub selection_set_graphql: String, |
| 165 | + pub parent_type_name: String, |
| 166 | + pub field_name: String, |
| 167 | + #[serde(default)] |
| 168 | + pub variables: HashMap<String, Value>, |
| 169 | +} |
| 170 | + |
| 171 | +/// `AppSyncPrevResult` contains the result of the previous step in a pipeline resolver. |
| 172 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 173 | +pub struct AppSyncPrevResult { |
| 174 | + #[serde(default)] |
| 175 | + pub result: HashMap<String, Value>, |
| 176 | +} |
| 177 | + |
| 178 | +/// `AppSyncIdentity` represents the identity of the caller as determined by the |
| 179 | +/// configured AppSync authorization mechanism (IAM, Cognito, OIDC, or Lambda). |
| 180 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 181 | +#[serde(untagged, rename_all = "camelCase")] |
| 182 | +pub enum AppSyncIdentity { |
| 183 | + IAM(AppSyncIamIdentity), |
| 184 | + Cognito(AppSyncCognitoIdentity), |
| 185 | + OIDC(AppSyncIdentityOIDC), |
| 186 | + Lambda(AppSyncIdentityLambda), |
| 187 | +} |
| 188 | + |
| 189 | +/// `AppSyncIdentityOIDC` represents identity information when using OIDC-based authorization. |
| 190 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 191 | +pub struct AppSyncIdentityOIDC { |
| 192 | + pub claims: Value, |
| 193 | + pub issuer: String, |
| 194 | + pub sub: String, |
| 195 | +} |
| 196 | + |
| 197 | +/// `AppSyncIdentityLambda` represents identity information when using AWS Lambda |
| 198 | +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] |
| 199 | +#[serde(rename_all = "camelCase")] |
| 200 | +pub struct AppSyncIdentityLambda { |
| 201 | + pub resolver_context: Value, |
| 202 | +} |
| 203 | + |
120 | 204 | #[cfg(test)]
|
121 | 205 | mod test {
|
122 | 206 | use super::*;
|
@@ -160,4 +244,14 @@ mod test {
|
160 | 244 | let reparsed: AppSyncLambdaAuthorizerResponse = serde_json::from_slice(output.as_bytes()).unwrap();
|
161 | 245 | assert_eq!(parsed, reparsed);
|
162 | 246 | }
|
| 247 | + |
| 248 | + #[test] |
| 249 | + #[cfg(feature = "appsync")] |
| 250 | + fn example_appsync_vtl_resolver() { |
| 251 | + let data = include_bytes!("../../fixtures/example-appsync-vtl-resolver.json"); |
| 252 | + let parsed: AppSyncResolverEvent = serde_json::from_slice(data).unwrap(); |
| 253 | + let output: String = serde_json::to_string(&parsed).unwrap(); |
| 254 | + let reparsed: AppSyncResolverEvent = serde_json::from_slice(output.as_bytes()).unwrap(); |
| 255 | + assert_eq!(parsed, reparsed); |
| 256 | + } |
163 | 257 | }
|
0 commit comments