Skip to content

Commit df4c279

Browse files
committed
document how to map appsync scalars to kotlin types
1 parent 135de17 commit df4c279

File tree

1 file changed

+17
-0
lines changed
  • src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions

1 file changed

+17
-0
lines changed

src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@ You can alternatively download the introspection schema using the [`fetch-schema
322322
4. Add this file to your project as directed by [Apollo documentation](https://www.apollographql.com/docs/kotlin/advanced/plugin-recipes#specifying-the-schema-location)
323323
</InlineFilter>
324324

325+
## Type Mapping AppSync Scalars
326+
By default, [AppSync Scalars](https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html#graph-ql-aws-appsync-scalars) will default to the `Any` type.
327+
You can map these scalars to more explicit types by editing the `apollo` block in your `app/build.gradle[.kts]` file. In the example below, we
328+
are now mapping a few of our AppSync scalar types to `String` instead of `Any`. Additional improvements could
329+
made writing [custom class adapters](https://www.apollographql.com/docs/kotlin/essentials/custom-scalars#define-class-mapping) to convert date/time scalars
330+
into Kotlin date/time class types.
331+
332+
```kotlin
333+
apollo {
334+
service("{serviceName}") {
335+
packageName.set("{packageName}")
336+
mapScalarToKotlinString("AWSDateTime")
337+
mapScalarToKotlinString("AWSEmail")
338+
}
339+
}
340+
```
341+
325342
### Performing Queries, Mutations, and Subscriptions with Apollo client
326343

327344
1. Navigate to the **Queries** tab in your API on the [AWS AppSync console](https://console.aws.amazon.com/appsync/home). Here, you can test queries, mutations, and subscriptions in the GraphQL playground.

0 commit comments

Comments
 (0)