# How can we avoid sending hardcoded format while reading fragment

**URL:** <https://community.apollographql.com/t/how-can-we-avoid-sending-hardcoded-format-while-reading-fragment/7951>\
**Category:** Client SDKs\
**Tags:** ios\
**Created:** [November 21, 2024, 3:43am UTC](https://community.apollographql.com/t/how-can-we-avoid-sending-hardcoded-format-while-reading-fragment/7951 "2024-11-21T03:43:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![P\_1433](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@P\_1433](https://community.apollographql.com/u/P_1433)\
**Post date:** [November 21, 2024, 3:43am UTC](https://community.apollographql.com/t/how-can-we-avoid-sending-hardcoded-format-while-reading-fragment/7951/1 "2024-11-21T03:43:11Z")

</div>

Is there a better way to send the non hardcode key as define below

ref: [Direct cache access - Apollo GraphQL Docs](https://www.apollographql.com/docs/ios/caching/cache-transactions) - Apollo Doc

```auto
let data = try transaction.readObject(
    ofType: HeroDetails.self,
    withKey: "Hero:123"
  )

```

The reason is when we update the sdk, we missed to change the cacheKey format and we hit into issue. Trying to avoid such things in future.

We set the format of cacheKeyInfo as below, as defined in doc.

```auto
cacheKeyInfo(for type: ApolloAPI.Object, object: ApolloAPI.ObjectData) -> CacheKeyInfo? {
   guard let id = object["id"] as? String else {
      return nil
    }
    return CacheKeyInfo(id: id)
}

```

---

<div class="post-metadata">

**Author:** ![calvincestari](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/calvincestari/32/339_2.png) [@calvincestari](https://community.apollographql.com/u/calvincestari)\
**Post date:** [November 21, 2024, 10:20pm UTC](https://community.apollographql.com/t/how-can-we-avoid-sending-hardcoded-format-while-reading-fragment/7951/2 "2024-11-21T22:20:11Z")

</div>

Hi @P_1433 - unfortunately there is no easy way to do this right now. Forming that cache key is a bit of implicit knowledge in knowing the format of the key ([such as this](https://github.com/apollographql/apollo-ios-dev/blob/main/apollo-ios/Sources/ApolloAPI/SchemaMetadata.swift#L60)) and it’s not particularly safe as a `String` either.

We recognize that we need to build a better way for users to derive a cache key in a type safe way. I suggest [creating an issue](https://github.com/apollographql/apollo-ios/issues/new/choose) to track this, it would benefit other users experiencing the same problem too.

---

<div class="post-metadata">

**Author:** ![P\_1433](https://avatars.discourse-cdn.com/v4/letter/p/e19adc/32.png) [@P\_1433](https://community.apollographql.com/u/P_1433)\
**Post date:** [November 22, 2024, 1:23am UTC](https://community.apollographql.com/t/how-can-we-avoid-sending-hardcoded-format-while-reading-fragment/7951/3 "2024-11-22T01:23:35Z")

</div>

Thanks for the information @calvincestari , will create an enhancement ticket.
