addTypename

abstract val addTypename: Property<String>

When to add __typename. One of "always", "ifAbstract", "ifPolymorphic" or "ifFragments"

  • "always": Add '__typename' for every composite field

  • "ifAbstract": Add '__typename' for abstract fields, i.e. fields that are of union or interface type

  • "ifPolymorphic": Add '__typename' for polymorphic fields, i.e. fields that contains a subfragment (inline or named) whose type condition isn't a super type of the field type. If a field is monomorphic, no '__typename' will be added. This adds the bare minimum amount of __typename but the logic is substantially more complex than ifAbstract.

  • "ifFragments" (deprecated): Add '__typename' for every selection set that contains fragments (inline or named) This causes cache misses when introducing fragments where no fragment was present before. This is deprecated and will be removed in a future version.

Apollo Kotlin requires __typename to handle polymorphism and parsing fragments. By default, __typename is added on every composite field selection set. When using the cache, this also ensures that cache keys can read __typename. If you're not using the cache or do not use __typename in your cache keys, you can use "ifAbstract" or "ifPolymorphic" to reduce the number of __typename and the size of the network response.

Default value: "ifFragments"