apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.36k stars 2.66k forks source link

useLazyQuerry being triggered by calling specific mutation #9907

Closed mak12 closed 1 year ago

mak12 commented 2 years ago

I have a following query

businessLeads(businessId: $businessIdToPass, leadLabelId: $leadLabelId)

and a mutation

contacted(id: $contactedId, businessId: $businesID)

here are the lazy query and mutation const [GetBusinessLeads] = useBusinessLeadsLazyQuery(); and const [CreateCallLogMutation] = useCreateCallLogMutation()

GetBusinessLeads is in previous screen, so whenever I call CreateCallLogMutation BusinessLeads query is triggered, I have tested it in every way possible, every other mutation and query works fine however as soon as createLog mutation is trigered it triggers GetBusinessLeads

useEffect(() => {
    if (businesses?.length) {
      setIsLoading(true);
      const {id} = businesses[0];
      let reqData: BusinessLeadsQueryVariables = {
        businessIdToPass: id,
        leadLabelId: selectedLead == 0 ? null : selectedLead,
      };
      GetBusinessLeads({variables: reqData})
        .then(res => {
          console.log('response ', res.data);
          setIsLoading(false);
          const leadsData = res.data?.businessLeads;
          setData(leadsData );
        })
        .catch(err => {
          setIsLoading(false);
        });
    }
  }, []);

Even useEffect is not triggered just the then body of promise of lazy query is triggered

Intended outcome: Calling CreateCallLogMutation shouldn't trigger any other query or mutation.

Actual outcome: whenever I call CreateCallLogMutation, It triggers GetBusinessLeads lazy query

Versions

System: OS: macOS 12.3.1 Binaries: Node: 18.0.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - ~/Desktop/Work/ReactProjects/upage/upageapp/node_modules/.bin/yarn npm: 8.6.0 - /opt/homebrew/bin/npm Browsers: Chrome: 103.0.5060.114 Safari: 15.4 npmPackages: @apollo/client: ^3.6.5 => 3.6.5 apollo: ^2.34.0 => 2.34.0 npmGlobalPackages: apollo: 2.34.0

bignimbus commented 1 year ago

Hi @mak12 👋🏻 thanks for your patience! I don't think we have enough information to narrow down what might be going wrong. There are plenty of scenarios where this could be expected behavior. Please provide a runnable reproduction that demonstrates the issue so that we can make a recommendation in specific terms. Thanks a bunch, looking forward to hearing from you 🙏🏻

github-actions[bot] commented 1 year ago

We're closing this issue now but feel free to ping the maintainers or open a new issue if you still need support. Thank you!

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.