fix(autocomplete): referenceText must not emit invalid MQL for unsafe field names#713
Open
Jacquelinezhong wants to merge 1 commit into
Conversation
… field names
Previously, toFieldCompletionItems() always emitted referenceText as
\`\$\${entry.path}\`, which produces invalid MQL for field names such as
"order-items", "my field", or "say\"hi\"" (e.g., \`\$order-items\`).
Fix: check each dot-separated path segment individually against
JS_IDENTIFIER_PATTERN.
- All segments valid → \`\$field.path\` (existing behaviour, e.g., \`\$address.city\`)
- Flat field with unsafe name → \`{ \$getField: "name" }\`
- Nested path with an unsafe segment → referenceText omitted (chained
\$getField form is complex; tracked as a follow-up in future-work.md)
FieldCompletionData.referenceText widened from required \`string\` to
optional \`string | undefined\` (\`referenceText?: string\`) so that tRPC
type inference on the client side stays consistent.
Closes microsoft#709
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #709
toFieldCompletionItems()previously emittedreferenceTextas`$${entry.path}`for every field, which produces invalid MQL for field names containing special characters (e.g.,$order-items,$my field).Changes:
JS_IDENTIFIER_PATTERNindividually (not the full path, so nested paths likeaddress.citykeep their valid$address.cityform)order-items) →{ $getField: "order-items" }order.item-count) →referenceTextomitted; chained$getFieldform is complex and tracked as a follow-up infuture-work.mdFieldCompletionData.referenceTextwidened fromstringtostring?so the tRPC client-side inferred type stays consistentfuture-work.mditem 2 marked as resolvedBehaviour table
age$age✅$age✅address.city$address.city✅$address.city✅order-items$order-items❌{ $getField: "order-items" }✅my field$my field❌{ $getField: "my field" }✅say"hi"$say"hi"❌{ $getField: "say\"hi\"" }✅order.item-count$order.item-count❌undefined✅ (no invalid MQL emitted)Test plan
toFieldCompletionItems.test.ts— 13 tests pass (3 new tests added for unsafe flat fields, unsafe nested paths, and safe nested paths)tsc --noEmit— no type errors🤖 Generated with Claude Code