question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nested fragment data returning null from cache

See original GitHub issue

Hello,

I am experiencing this issue in React Native using Apollo Client: I have a query containing a fragment and in it a nested fragment; when the query runs the first time (empty cache) the result is returned correctly and I can see data inside the fragment and the nested fragment; on the following rendering, when the result returns from the cache (default fetchPolicy), data is correctly returned except the nested fragment which contains “null”. I don’t manually manipulate the cache in any way on this query and we have no inMemoryCache configuration for it or its fields.

The nested fragment does NOT have an id but I tried setting a keyField on another field and nothing changed. Removing the cache (fetchPolicy=no-cache) solves the problem but we want to use it.

Do you know what can cause the nested fragment data to be null in this situation or similar?

Here is a query example that resemble our query:

query MyData($myParam: String!) {
  getMyData(myParam: $myParam) {
    categories {
      catOne {
        ...MyFragmentOne
      }
      catTwo {
        ...MyFragmentOne
      }
      catThree {
        ...MyFragmentOne
      }
    }
    brands {
      brandOne {
        ...Brand
      }
      BrandTwo {
        ...Brand
      }
      BrandThree {
        ...Brand
      }
    }
  }
}
fragment Brand on Brand {
  id
  name
  keywords {
    ...Keywords
  }
}

fragment Keywords on Keywords {
  lang1
  lang2
}`

Keywords is the data fragment returning null from the cache,

Versions I am are experiencing this in React Native using version ‘3.3.19’, I also tested using ‘3.4’ and the latest ‘3.6.9’ with the same result.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrclaycommented, Sep 18, 2022

I also wasted hours before figuring out the missing possibleTypes config.

1reaction
dylanwulfcommented, Aug 1, 2022

Shot in the dark here, but have you set up the possibleTypes configuration for your schema’s unions and interfaces?

nope, no possibleTypes defined so far in this project. thanks

Ah ok. If any of those fragments use a type that implements an interface, or is part of a union, then adding possibleTypes might help. If you’re not using any unions or interfaces then I’m not sure what’s wrong.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading cached data failed for some reason(solved) - Help
The cachedVotes returned the cached value I wanted, but the other fragment ... These are the two fragments, a nested fragment structure, ...
Read more >
Why getContext() in fragment sometimes returns null?
When the fragment is not yet attached, or was detached during the end of its lifecycle, getContext() will return null .
Read more >
View - Android Developers
Summary: Nested Classes | XML Attrs | Constants | Fields | Ctors | Methods ... A ViewGroup is a special view that can...
Read more >
Spring Data JDBC - Reference Documentation
This document is the reference guide for Spring Data JDBC Support. ... The absence of a query result is then indicated by returning...
Read more >
ViewPager with FragmentPagerAdapter - CodePath Cliffnotes
A ViewPager is a layout which can be added to any layout XML file inside a ... Below shows us how to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found