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

InMemoryCache: store fields with an empty object of optional arguments the same as fields without arguments #12370

Open
wants to merge 2 commits into
base: release-3.13
Choose a base branch
from

Conversation

phryneas
Copy link
Member

Fixes #12365
Fixes #8853

Copy link

changeset-bot bot commented Feb 13, 2025

🦋 Changeset detected

Latest commit: bdf82ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svc-apollo-docs
Copy link

svc-apollo-docs commented Feb 13, 2025

⚠️ Docs preview not attached to branch

The preview was not built because the PR's base branch release-3.13 is not in the list of sources.

An Apollo team member can comment one of the following commands to dictate which branch to attach the preview to:

  • !docs set-base-branch version-2.6
  • !docs set-base-branch main

Build ID: 1a2be862126572b9471c46aa

Copy link

pkg-pr-new bot commented Feb 13, 2025

npm i https://pkg.pr.new/@apollo/client@12370

commit: bdf82ed

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit bdf82ed
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67adfa0c41f88100072b44e8
😎 Deploy Preview https://deploy-preview-12370--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Feb 13, 2025

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 41.26 KB (+0.05% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 50.73 KB (+0.05% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 47.8 KB (+0.06% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 36.27 KB (+0.06% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 33.67 KB (+0.08% 🔺)
import { ApolloProvider } from "dist/react/index.js" 1.26 KB (0%)
import { ApolloProvider } from "dist/react/index.js" (production) 1.24 KB (0%)
import { useQuery } from "dist/react/index.js" 5.21 KB (0%)
import { useQuery } from "dist/react/index.js" (production) 4.3 KB (0%)
import { useLazyQuery } from "dist/react/index.js" 5.71 KB (0%)
import { useLazyQuery } from "dist/react/index.js" (production) 4.78 KB (0%)
import { useMutation } from "dist/react/index.js" 3.62 KB (0%)
import { useMutation } from "dist/react/index.js" (production) 2.84 KB (0%)
import { useSubscription } from "dist/react/index.js" 4.43 KB (0%)
import { useSubscription } from "dist/react/index.js" (production) 3.48 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" 5.88 KB (0%)
import { useSuspenseQuery } from "dist/react/index.js" (production) 4.54 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" 5.37 KB (0%)
import { useBackgroundQuery } from "dist/react/index.js" (production) 4.04 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" 5.46 KB (0%)
import { useLoadableQuery } from "dist/react/index.js" (production) 4.11 KB (0%)
import { useReadQuery } from "dist/react/index.js" 3.42 KB (0%)
import { useReadQuery } from "dist/react/index.js" (production) 3.37 KB (0%)
import { useFragment } from "dist/react/index.js" 2.37 KB (0%)
import { useFragment } from "dist/react/index.js" (production) 2.32 KB (0%)

@@ -202,7 +202,8 @@ export abstract class EntityStore implements NormalizedCache {

public modify(
dataId: string,
fields: Modifier<any> | Modifiers<Record<string, any>>
fields: Modifier<any> | Modifiers<Record<string, any>>,
exact: boolean
Copy link
Member Author

@phryneas phryneas Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opted to add exact only to our internal api and not expose it.
Userland code can still compare the storeFieldName and fieldName values passed into the modifier function to reach this goal, and we should probably not encourage people to write code like

cache.modify(id, {
  fields: {
    ['myField({"complex":....})']() {
      /* ... */
    },
  },
});

in the first place.
There is would be slightly more sane to use

cache.modify(id, {
  fields: {
    myField(value, { storeFieldName }) {
      if (storeFieldName === 'myField({"complex":....})') {
        /* ... */
      }
    },
  },
});

instead.

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

Successfully merging this pull request may close these issues.

2 participants