Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apollo return same data even datatype and url is changed through variables #304

Open
Tjajeer opened this issue Dec 20, 2022 · 1 comment

Comments

@Tjajeer
Copy link

Tjajeer commented Dec 20, 2022

I am creating generic queries for all our one module

  query executeRest($path: String!, $dataType: String!) {
    results: executeRest @rest(type: $dataType, path: $path) {
      results
      message
    }
  }

at one place we call it

      variables: {
        path: "/api/people",
        dataType: "people",
      }

at another places

      variables: {
        path: "/api/sections",
        dataType: "sections",
      }

when we call second api that is sections its modifying the people api data as well

@fbartho
Copy link
Collaborator

fbartho commented Dec 20, 2022

I think ApolloClient (Upstream) doesn’t realize that the $path or dataType is a cache-busting value.

Apollo has a cacheKey method/api that you can configure to dynamically set the cache-id. I recommend you examine these docs: https://www.apollographql.com/docs/react/caching/cache-configuration#customizing-cache-ids

Generally I wouldn’t recommend making the path dynamic unless the response is safe to store in the same Normalized Cache entry. This also means you probably don’t want the dataType to ever be dynamic. You may be able to work around this issue with the above apis!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants