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

Merged
merged 3 commits into from
Jul 17, 2025

Conversation

phryneas
Copy link
Member

Fixes #12365
Fixes #8853

Copy link

changeset-bot bot commented Feb 13, 2025

🦋 Changeset detected

Latest commit: 40599b3

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

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/apollographql/apollo-client/@apollo/client@12370

commit: 40599b3

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
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.81 KB (+0.11% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.92 KB (-0.05% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.67 KB (+0.09% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 27.1 KB (+0.29% 🔺)
import { ApolloProvider } from "@apollo/client/react" 5.7 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 960 B (0%)
import { useQuery } from "@apollo/client/react" 6.99 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 2.23 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 6.88 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.13 KB (0%)
import { useMutation } from "@apollo/client/react" 6.22 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 1.48 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.57 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 1.81 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.34 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.62 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.13 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.38 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.07 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.36 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.37 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.62 KB (0%)
import { useFragment } from "@apollo/client/react" 6.45 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.69 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!

@jerelmiller jerelmiller changed the base branch from main to release-4.0 July 17, 2025 20:59
@jerelmiller jerelmiller force-pushed the pr/fieldnames-empty-argument branch from 3ca1179 to 40599b3 Compare July 17, 2025 21:47
@github-actions github-actions bot added the auto-cleanup 🤖 label Jul 17, 2025
@apollo-librarian
Copy link

apollo-librarian bot commented Jul 17, 2025

⚠️ Docs preview not attached to branch

The preview was not built because the PR's base branch release-4.0 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: 64e287b93ce9880bd7b7da8f

@jerelmiller jerelmiller merged commit 0517163 into release-4.0 Jul 17, 2025
46 checks passed
@jerelmiller jerelmiller deleted the pr/fieldnames-empty-argument branch July 17, 2025 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Field is cached separately when args are not set vs set to null InMemoryCache: Data with null arguments not merged with data without arguments in
3 participants