Skip to content

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

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

Open
wants to merge 3 commits into
base: main
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: 3ca1179

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 failed

The preview failed to build.

Build ID: da8a08760232a3773e0b2cce

Errors

react/data/subscriptions

  • Cannot find module '@microsoft/tsdoc/schemas/tsdoc.schema.json' from '/var/task/node_modules/.pnpm/@microsoft[email protected]/node_modules/@microsoft/tsdoc-config/lib'

Copy link

pkg-pr-new bot commented Feb 13, 2025

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

commit: 3ca1179

Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 3ca1179
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/67cfff39a8a682000872d98a
😎 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.

@jerelmiller jerelmiller changed the base branch from release-3.13 to main March 10, 2025 17:31
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

Looks good to me!

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