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.

Deduplication/Batching not properly handling duplicate queries

See original GitHub issue

Given 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 on queryId 1
    • So queryId 1 resolves and updates the first component, but queryId 2 never resolves and stays in a loading state
  • Without deduplication
    • Two requests are sent (with a queryId of 1 and 2)
    • The next handler is called twice, with queryId 1 and 2
    • Both queries resolve and both components update as expected

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:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Wenzilcommented, Nov 16, 2017

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?

1reaction
Wenzilcommented, Nov 7, 2017

Query deduplication not working with HttpLink either

Read more comments on GitHub >

github_iconTop 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 >

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