Join us for GraphQL Summit, October 10-12 in San Diego. Super Early Bird registration ends soon!
Try Apollo Studio
You're viewing documentation for a previous version of this software. Switch to the latest stable version.

Custom scalar types

Apollo supports custom scalar types, such as Date.

You first need to define the mapping in your build.gradle file. This maps from the GraphQL type to the Java/Kotlin class to use in code.

apollo {
customTypeMapping = [
"Date" : "java.util.Date"
apollo {
"Date" to "java.util.Date"

Next, register your custom adapter and add it to your ApolloClient builder:

val dateCustomTypeAdapter = object : CustomTypeAdapter<Date> {
override fun decode(value: CustomTypeValue<*>): Date {
return try {
} catch (e: ParseException) {
throw RuntimeException(e)
override fun encode(value: Date): CustomTypeValue<*> {
return GraphQLString(DATE_FORMAT.format(value))
.addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter)
Edit on GitHub
UI Tests
Using without apollo-runtime