facebook / relay

Relay is a JavaScript framework for building data-driven React applications.
https://relay.dev
MIT License
18.24k stars 1.8k forks source link

Generating client mock-data in `MockPayloadGenerator` does not work due to wrong partitioning when `generateDeferredPayload = true`. #4712

Open jakobkhansen opened 5 days ago

jakobkhansen commented 5 days ago

Hi,

I am seeing an issue with using mockClientData: true with MockPayloadGenerator.generateWithDefer. When generating mock-data for client extensions, Relay generates an object with the following structure:

{
    "path": [],
    "label": undefined,
    "data": {
       ...
    }
}

and it seems Relay misidentifies this as an incremental update in the partitionGraphQLResponses function. The invariant there fails and crashes since the path is not null, but the label is.

jakobkhansen commented 5 days ago

Tagging @gorodscy, it looks like this is hitting the STREAM/DEFER case when both mockClientData and generateDeferredPayload options are true, leading to all client mock-data being generated as deferred data when it shouldn't. Maybe these should be separate cases?