Add section in docs for child read functions with @client fields - #12931
Add section in docs for child read functions with @client fields#12931jerelmiller wants to merge 4 commits into
read functions with @client fields#12931Conversation
|
commit: |
size-limit report 📦
|
✅ Docs preview readyThe preview is ready to be viewed. View the preview File Changes 0 new, 1 changed, 0 removedBuild ID: 52ce29ebfe3b38191b5a0288 URL: https://www.apollographql.com/docs/deploy-preview/52ce29ebfe3b38191b5a0288 |
a323f2d to
907bb15
Compare
phryneas
left a comment
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
}lengthis defined as the number or arguments before the first optional argument, solength == 0means either spread arguments, no arguments or default arguments- JS identifiers are specified here https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#prod-IdentifierName and if we ignore identifiers with a
UnicodeEscapeSequence,[\p{ID_Start}$_][\p{ID_Continue}$]*should match all of them
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?)
|
Going a different direction with #12934 |
Closes #12930