relay icon indicating copy to clipboard operation
relay copied to clipboard

Creating new RecordSource with __RELAY_RESOLVER__ data

Open roduyemi opened this issue 7 months ago • 2 comments

Hello, we are implementing HTML streaming with React and Relay. We create a new environment on the server and take a snapshot of the store data with the following:

const initialRelayData = environment.getStore().getSource().toJSON();

We then use this cached data on the client to create a new environment:

const recordSource = new RecordSource(initialRelayData);

const store = new Store(recordSource, {
    gcReleaseBufferSize: 1000,
});

const network = createNetworkLayer({
    headers
});

return new Environment({
    network,
    store,
    missingFieldHandlers,
    relayFieldLogger,
    isServer,
});

However, when fetching data with fetchQuery, any query that corresponds with cached data from the store that includes the __typename __RELAY_RESOLVER__, results in no data being returned. We have tried updating the default fetchPolicy from network-only to store-or-network but get the same result.

Omitting data with __typename __RELAY_RESOLVER__ from our cache (initialRelayData) before creating a new RecordSource results in the correct data returned from our queries.

Any ideas why this might be? Thanks!

roduyemi avatar Sep 17 '25 09:09 roduyemi

Thanks for the report. I think we should probably filter these records out of the store when serializing to JSON. Would you be up to opening a PR that does this (see RelayRecordSource.js) with a runtime feature flag to opt out?

captbaritone avatar Sep 25 '25 16:09 captbaritone

Thanks for the report. I think we should probably filter these records out of the store when serializing to JSON. Would you be up to opening a PR that does this (see RelayRecordSource.js) with a runtime feature flag to opt out?

Thanks @captbaritone, I'll have a go at raising a PR to do this next week.

roduyemi avatar Sep 26 '25 09:09 roduyemi