From 19b650125417c2d1716a668d7a92c63a57d44dfe Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Tue, 21 Jan 2025 08:32:42 -0500 Subject: [PATCH] [Android] Document how to map AppSync Scalars to Kotlin types (#8205) * document how to map appsync scalars to kotlin types --- .../data/aws-appsync-apollo-extensions/index.mdx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx b/src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx index b7068f5ad97..53327933062 100644 --- a/src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/aws-appsync-apollo-extensions/index.mdx @@ -320,6 +320,19 @@ You can alternatively download the introspection schema using the [`fetch-schema 2. On the left side, select Schema 3. When viewing your schema, there should a “Export schema” drop down. Select this and download the `schema.json` file. 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) + +### Type Mapping AppSync Scalars +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. + +```kotlin +apollo { + service("{serviceName}") { + packageName.set("{packageName}") + mapScalarToKotlinString("AWSDateTime") + mapScalarToKotlinString("AWSEmail") + } +} +``` ### Performing Queries, Mutations, and Subscriptions with Apollo client