# cache.readFragment only returning \_\_typename

**URL:** https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658
**Category:** Client SDKs
**Tags:** client, web
**Created:** [August 29, 2023, 10:48pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658 "2023-08-29T22:48:42Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![abrenoch](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abrenoch/32/4544_2.png) [@abrenoch](https://community.apollographql.com/u/abrenoch)
#### Post date: [August 29, 2023, 10:48pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/1 "2023-08-29T22:48:42Z")

</div>

Hi, new to apollo and really struggling to understand some of the things I am seeing.

I have this query:

```auto
    query {
        getUserCollectionListing {
            edges {
                node {
                    id
                    owner
                    name
                    items {
                        ... on object_Metadata {
                            id
                            __typename
                        }
                    }
                    __typename
                }
            }
        }
    }

```

Which is used like so:

```auto
    const { loading, error, data, refetch } = useQuery(GET_USER_BASKETS, {
        fetchPolicy: 'network-only'
    });

```

I am trying to access the cache for this query using ‘readFragment’:

```auto
        cache.readFragment({
            id: currentBasket, // looks like: object_UserCollection:822134
            
            fragment: gql`
                fragment Object_UserCollectionFragment on Object_UserCollection {
                id
                name
                owner
                items
                __typename
                }
            `,
            // fragmentName: 'Object_UserCollectionFragment', // tried with and without
        });

```

But the problem is the object returned by ‘readFragment’ is _not complete_, and only contains the ‘\_\_typename’:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/apollographql/original/2X/a/a42b0c163a7ffc1d9c9ccc262b83a1f7da8cdb4a.png)

I feel like I have circled the documentation and examples endlessly and I don’t understand why this would be the case. What would cause the rest of that entry to be missing?

‘cache.readQuery’ on 'GET\_USER\_BASKETS` appears to returned the cached data, so I can get it from there if needed, but I would really like to understand the behavior I’m seeing.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)
#### Post date: [August 29, 2023, 10:55pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/2 "2023-08-29T22:55:34Z")

</div>

Hey @abrenoch 👋

Can you check to see what the contents of your cache looks like? You can dump the cache to the console using the `client.extract()` or `client.cache.extract()` function.

```js
console.log(client.extract())

```

You should see a record with key `object_UserCollection:822134` in there. Can you verify the data you expect for that record is available in the cache?

---

<div class="post-metadata">

### Author: ![abrenoch](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abrenoch/32/4544_2.png) [@abrenoch](https://community.apollographql.com/u/abrenoch)
#### Post date: [August 29, 2023, 11:22pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/3 "2023-08-29T23:22:50Z")

</div>

Hey there, really appreciate the fast response!

I can confirm the items exist in the cache as expected:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/apollographql/original/2X/e/e90d1854b4943dc8aa69adf34327d911cca78ca1.png)

Maybe something with how the fragment is formatted? I feel like there has to be something simple or obvious I’m overlooking.

---

<div class="post-metadata">

### Author: ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)
#### Post date: [August 29, 2023, 11:26pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/4 "2023-08-29T23:26:25Z")

</div>

Something I’m noticing that _might_ be the problem here is that it looks like `items` might be an array and your fragment has no subselection on that field. See if adding a subselection fixes it.

```graphql
fragment Object_UserCollectionFragment on Object_UserCollection {
  # ...
  items {
    __typename
  }
}

```

---

<div class="post-metadata">

### Author: ![abrenoch](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abrenoch/32/4544_2.png) [@abrenoch](https://community.apollographql.com/u/abrenoch)
#### Post date: [August 29, 2023, 11:37pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/5 "2023-08-29T23:37:00Z")

</div>

I like the idea, but unfortunately didnt seem to help. I also tried omitting the ‘items’ property entirely to no avail.

---

<div class="post-metadata">

### Author: ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)
#### Post date: [August 29, 2023, 11:40pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/6 "2023-08-29T23:40:13Z")

</div>

Bummer! As a debugging measure, perhaps add one field at a time to the fragment to see if you’re able to get any data from any of the fields. If you’re still not successful with even a single field, you might consider opening an issue with a reproduction for us to look at.

---

<div class="post-metadata">

### Author: ![abrenoch](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/abrenoch/32/4544_2.png) [@abrenoch](https://community.apollographql.com/u/abrenoch)
#### Post date: [August 29, 2023, 11:49pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/7 "2023-08-29T23:49:02Z")

</div>

Oh man, I just found the problem 🤡

‘Object\_UserCollection’ should have been ‘object\_UserCollection’ in my fragment. Correcting it there fixed my issue.

I spent too long on that, how embarrassing lol. Maybe enough for tonight 😄

Thank you for your prompt replies, I appreciate it more than you know!

---

<div class="post-metadata">

### Author: ![jerelmiller](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jerelmiller/32/3314_2.png) [@jerelmiller](https://community.apollographql.com/u/jerelmiller)
#### Post date: [August 30, 2023, 2:40am UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/8 "2023-08-30T02:40:26Z")

</div>

I always say the hardest bugs to solve require the smallest code changes 🤣. I can’t tell you how many times this has happened to me! Glad you found the issue!

---

<div class="post-metadata">

### Author: ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)
#### Post date: [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/cache-readfragment-only-returning-typename/6658/9 "2025-02-06T20:48:21Z")

</div>


