Skip to content

Commit 19b6501

Browse files
authored
[Android] Document how to map AppSync Scalars to Kotlin types (#8205)
* document how to map appsync scalars to kotlin types
1 parent 386358a commit 19b6501

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,19 @@ You can alternatively download the introspection schema using the [`fetch-schema
320320
2. On the left side, select Schema
321321
3. When viewing your schema, there should a “Export schema” drop down. Select this and download the `schema.json` file.
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)
323+
324+
### Type Mapping AppSync Scalars
325+
By default, [AWS AppSync Scalars](https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html#graph-ql-aws-appsync-scalars) will default to the `Any` type. 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 are now mapping a few of our AppSync scalar types to `String` instead of `Any`. Additional improvements could be made by writing [custom class adapters](https://www.apollographql.com/docs/kotlin/essentials/custom-scalars#define-class-mapping) to convert date/time scalars into Kotlin date/time class types.
326+
327+
```kotlin
328+
apollo {
329+
service("{serviceName}") {
330+
packageName.set("{packageName}")
331+
mapScalarToKotlinString("AWSDateTime")
332+
mapScalarToKotlinString("AWSEmail")
333+
}
334+
}
335+
```
323336
</InlineFilter>
324337

325338
### Performing Queries, Mutations, and Subscriptions with Apollo client

0 commit comments

Comments
 (0)