cypher-codegen: infer nullability for SET-clause params#78
Merged
Conversation
QueryAnalyzer.extractParams typed params only from node-pattern property
maps (Pass 1) and `expr.prop IN $param` list expressions (Pass 2). Params
bound via a SET clause (`MATCH (n:Label {...}) SET n.prop = $param`) were
not analyzed, so they fell back to a non-nullable `String`, even when
assigned to an optional vertex property that must accept `null`.
Add Pass 3, mirroring Pass 1 over SET items: resolve `<var>.<prop>` to a
labelled schema property via the existing buildVarLabelMap / lookupParamType,
emitting the property's type and nullability. Only the
`propertyExpression ASSIGN expression` alternative is handled, so map-merge
(`SET n += $map`) is naturally excluded; the shared seenParams set prevents
double-counting a param used in both a pattern and a SET. Unresolvable
left-hand sides keep the prior non-nullable `String` fallback.
Covered by new unit tests in QueryAnalyzer.node.unit.test.ts.
Generated with AI
Co-Authored-By: AI <ai@example.com>
Minor bump: parameters bound in a SET clause now infer their type and nullability from the schema. Generated with AI Co-Authored-By: AI <ai@example.com>
Merged
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.
Problem
QueryAnalyzer.extractParamstyped query parameters from two sources only:(n:Label {prop: $p})(coversCREATE/MATCHconstraints).expr.prop IN $paramlist expressions.Params bound via a
SETclause —MATCH (n:Label {id: $id}) SET n.prop = $p— were not analyzed. The backend regex scan still surfaced the param name, so it appeared in the generated signature, but with the fallback type{ type: "String", nullable: false }.Net effect: a param assigned to an optional vertex property was typed non-nullable (e.g.
prop: string) when it should beprop: string | null— the adapter must be able to persistnullto clear such a property.Fix
Add a Pass 3 to
extractParams, mirroring Pass 1 but walkingSETitems:SetItemContextnodes, handling only thepropertyExpression ASSIGN expressionalternative (<var>.<prop> = $param).<var>→ label via the existingbuildVarLabelMap, then types the param vialookupParamTypeexactly as Pass 1 does — emitting the property'stypeandnullableflag.SET n += $map(map-merge) is naturally excluded: that alternative has nopropertyExpression(), so it never enters Pass 3 (map params remain a separate feature).seenParamsset prevents double-counting a param used in both a pattern and aSET.Stringfallback, so behaviour is unchanged for untyped params.Tests
New
describe("analyzeQuery — SET-clause param nullability")block inQueryAnalyzer.node.unit.test.ts, written test-first (verified red for the right reason — SET params were absent from analyzer output — before implementing):nullable: true.nullable: false.SETtypes each item independently.MATCHpattern and aSETis not double-counted.Existing Pass 1 (
CREATE/MATCH) and Pass 2 (IN) param typing is unchanged. Full package unit suite: 178/178 green;pnpm checkclean.Release
Changeset included: minor bump for
@evryg/effect-cypher-codegen(0.2.0→0.3.0).Commits
cypher-codegen: infer nullability for SET-clause params— Pass 3 implementation + unit testscypher-codegen: changeset for SET-clause param nullability— release changeset