Deduplication/Batching not properly handling duplicate queries
See original GitHub issueGiven a single query and using query batching (with apollo-link-batch-http
):
const client = new ApolloClient({
link: new BatchHttpLink({
uri: "https://api.graph.cool/simple/v1/cj96xwateatkv01264g1xith2"
})
});
class App extends Component {
render() {
return (
<ApolloProvider client={client}>
<div>
<GreetUser id="cj96ydmq34cqj0104r5ddv66a" />
<GreetUser id="cj96ydmq34cqj0104r5ddv66a" />
</div>
</ApolloProvider>
);
}
}
class Greeter extends Component {
render() {
return (
<div>
{this.props.data.loading
? "Loading..."
: `Hi ${this.props.data.People && this.props.data.People.login}!`}
</div>
);
}
}
const query = gql`
query People($id: ID!) {
People(id: $id) {
id
login
}
}
`;
const GreetUser = graphql(query, {
options: props => ({
fetchPolicy: "cache-and-network",
variables: { id: props.id }
})
})(Greeter);
export default App;
Intended outcome:
Executing the query multiple times should properly resolve, so the App
component above should display “Hi Dylan!” twice.
Actual outcome:
Only the first component using the query resolves. The rest get hung in a loading state. So the App
component above displays “Hi Dylan! Loading…”
If I turn set queryDeduplication
to false, it works fine. But regardless of it being true/false, both queries are sent to the API server anyway.
After digging into fetchRequest on the QueryManager
- With deduplication enabled
- Two requests are sent (with a
queryId
of 1 and 2) - The
next
handler is called twice, but both times onqueryId
1 - So
queryId
1 resolves and updates the first component, butqueryId
2 never resolves and stays in a loading state
- Two requests are sent (with a
- Without deduplication
- Two requests are sent (with a
queryId
of 1 and 2) - The
next
handler is called twice, withqueryId
1 and 2 - Both queries resolve and both components update as expected
- Two requests are sent (with a
How to reproduce the issue:
I threw a create-react-app project together: https://github.com/dmarkow/apollo-batching-issue
Version
- apollo-client@2.0.1
- apollo-link-batch-http@1.0.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Handle duplicate data in Azure Data Explorer | Microsoft Learn
Solution #2: Handle duplicate rows during query Another option is to filter out the duplicate rows in the data during query. The arg_max() ......
Read more >How To Deal with Duplicate Entries Using SQL
A simple SQL query allows you to retrieve all duplicates present in a data table. Looking at some particular examples of duplicate rows...
Read more >Handling duplicate data in streaming pipeline using Pub/Sub ...
How to handle duplicate data in your streaming data pipeline using Pub/Sub and Dataflow.
Read more >SQL - Handling Duplicates - Tutorialspoint
The basic syntax of a DISTINCT keyword to eliminate duplicate records is as follows. SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [ ...
Read more >Remove Duplicate Does not Work in Power Query ... - YouTube
One of the most common transformations in Power Query is the Remove Duplicates. This transformation is used in many scenarios, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Neat! In the meantime I had to
yarn upgrade apollo-link-dedup@latest
and manually delete the old version from apollo-client’s node_modules. Is there a better way?Query deduplication not working with
HttpLink
either