VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
http://vulcanjs.org
MIT License
7.98k stars 1.89k forks source link

Duplicate Item with withMulti #2719

Closed IBRAHIMDANS closed 10 months ago

IBRAHIMDANS commented 3 years ago

Describe the bug Hola, I have a problem with withMulti2 when I make a request by limiting. I have data which is duplicated in result node v14.16.1 vulcan

To Reproduce Steps to reproduce the behavior:

1 - withMulti2( ... limit: 3)([component])

2 - in my component call loadMoreInc() after result content duplicated item

eric-burel commented 3 years ago

According to the code from your PR, this is a backend issue => the multi resolver is sending the same item twice, as if the limit was taken into account incorectly

GraemeFulton commented 3 years ago

useMulti2 in meteor seems to work for me, but useMulti from vulcanjs/hooks is not getting the filter after loadmore.

I am filtering documents by userId (and a template type field), and I can see that in the first query (before loadmore), all filter and userId is present:

Screenshot 2021-06-17 at 13 08 35

After loadMore button clicked, the query no longer has the filter at all:

Screenshot 2021-06-17 at 13 05 53

So I'm just looking into that now 🤓

GraemeFulton commented 3 years ago

I have tracked it down to here: https://github.com/VulcanJS/vulcan-npm/blob/98b23f1ea04b18c39b036faafb075951b4bd4549/packages/react-hooks/multi.ts#L182

in fetchMore, I don't see the filter, only the input with offset:

 return fetchMore({ 
     variables: { input: offsetInput },        
     updateQuery: fetchMoreUpdateQuery(resolverName),     
     });

Setting it up locally looks like there is a few steps and maybe a learning curve: https://github.com/VulcanJS/vulcan-next/blob/devel/src/content/docs/contributing.md. I haven't got time right now to dig further, so will come back to it next week and continue on other parts first

eric-burel commented 3 years ago

@GraemeFulton will be fixed by https://github.com/VulcanJS/vulcan-npm/pull/56/files (edit: released just now in "0.2.1" of react-hooks)

@IBRAHIMDANS the issue is that variables are not correclty merged in the hook, so in the loadMore/loadMoreInc calls, it indeed loses the filter. Instead of using "uniq", the solution is to fix the variable merging pattern, you can take a look at the PR: https://github.com/VulcanJS/vulcan-npm/pull/56/files

To fix this: