Skip to content

Add section in docs for child read functions with @client fields - #12931

Closed
jerelmiller wants to merge 4 commits into
mainfrom
jerel/local-state-doc
Closed

Add section in docs for child read functions with @client fields#12931
jerelmiller wants to merge 4 commits into
mainfrom
jerel/local-state-doc

Conversation

@jerelmiller

Copy link
Copy Markdown
Member

Closes #12930

@jerelmiller
jerelmiller requested a review from a team as a code owner September 19, 2025 18:05
@changeset-bot

changeset-bot Bot commented Sep 19, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bad9fbd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2025

Copy link
Copy Markdown
npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@12931

commit: bad9fbd

@github-actions

github-actions Bot commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.84 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.8 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.65 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.81 KB (0%)
import { ApolloProvider } from "@apollo/client/react" 5.91 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 994 B (0%)
import { useQuery } from "@apollo/client/react" 7.35 KB (0%)
import { useQuery } from "@apollo/client/react" (production) 2.38 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 7.11 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.16 KB (0%)
import { useMutation } from "@apollo/client/react" 6.47 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 1.52 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.79 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 1.82 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.55 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.63 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.34 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.4 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.29 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.39 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.6 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.65 KB (0%)
import { useFragment } from "@apollo/client/react" 6.66 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.71 KB (0%)

@apollo-librarian

apollo-librarian Bot commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

✅ Docs preview ready

The preview is ready to be viewed. View the preview

File Changes

0 new, 1 changed, 0 removed
* (developer-tools)/react/(latest)/local-state/managing-state-with-field-policies.mdx

Build ID: 52ce29ebfe3b38191b5a0288
Build Logs: View logs

URL: https://www.apollographql.com/docs/deploy-preview/52ce29ebfe3b38191b5a0288

@phryneas phryneas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Definitely something we need documented, let's get this in


</ExpansionPanel>

To provide default values for `read` functions on `@client` fields, use the nullish coalescing operator:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this something we can help with by providing a dev-only warning?

It's a bit tricky, but this should catch most cases:

const no_args_or_spread_function = /^(function\s+)?([\p{ID_Start}$_][\p{ID_Continue}$]*\s*)?\(\s*([)]|\.\.\.[\p{ID_Start}$_][\p{ID_Continue}$]*)/u
if (readPolicyFn.length === 0 && !readPolicyFn.toString().match(no_args_or_spread_function)) {
  // warn about using default arguments
}

I think this should eliminate all weird one-offs, but an additional check for a general function shape of the string might make it even more solid so it doesn't warn on engine builtins (but why would one pass those in there?)

@github-actions github-actions Bot added the auto-cleanup 🤖 label Sep 22, 2025
@jerelmiller
jerelmiller marked this pull request as draft September 22, 2025 16:31
@jerelmiller

Copy link
Copy Markdown
Member Author

Going a different direction with #12934

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect resolution of nested @client fields in v4

2 participants