facebook / facebook/relay

useLazyLoadQuery does not prevent sending empty requests to server when using store-and-network

Open
#5,126 0 comments 0 reactions 0 assignees View on GitHub
shared with relay team
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Consider the following useLazyLoadQuery:
```
const data = useLazyLoadQuery(
graphql`
query TodoQuery($id: ID!, $visible: Boolean!) {
todo(id: $id) @include(if: $visible) {
id
}
}
`,
{
id: "",
visible: false,
},
{
fetchPolicy: "store-and-network",
}
);
```

When using fetchPolicy store-or-network no request is made due to the fact that the resulting selection is empty.

When we instead try to use store-and-network an empty unnecessary query is made to the server.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided useLazyLoadQuery example with the store-and-network and store-or-network fetch policies, then trace the useLazyLoadQuery entry point and the handling of empty selections. Done means store-and-network no longer sends an unnecessary empty request while the query's normal network behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.