7.9 Writing projected types inside a query — one query is a pipeline
A query may CREATE and MERGE projected types (§7.8), and SET what it made. The writes land in
the run’s scratch: the rest of the same query sees them, as Cypher’s read-your-writes promises, no other
run ever does, and nothing reaches the store. “Read-only” on the query surfaces means read-only with
respect to the store.
That is what makes one ordinary query a pipeline: project text, build on it, read what was built.
CALL ai.fromText($notes, '(t:Attendee)-[:RAISED]->(i:Issue), (t)-[:WORKS_FOR]->(a:CustomerAccount)') YIELD t, i, aWITH DISTINCT i, aMATCH (a)-[:HAS_CASE]->(c:SupportCase) WHERE c.status IN ['open', 'pending']WITH i, relevant(c, 'the same problem as: ' + i.summary) AS trackedUNWIND tracked AS tcCREATE (i)-[:TRACKED_BY]->(tc)WITH count(*) AS linkedMATCH (t2:Attendee)-[:RAISED]->(untracked:Issue)WHERE NOT EXISTS { (untracked)-[:TRACKED_BY]->() }RETURN untracked.summary, untracked.severity, t2.name, t2.roleAttendee and Issue are projected types with no stored instances, so MATCH (untracked:Issue) reads
exactly what this run made — the label is the isolation. Steps can also be written as unit subqueries,
each run in order:
CALL { CALL ai.fromText($email, '(t:Attendee)-[:RAISED]->(i:Issue)') YIELD t RETURN count(*) AS projected }CALL { MATCH (i:Issue) … CREATE (i)-[:TRACKED_BY]->(c) RETURN count(*) AS linked }MATCH (u:Issue) WHERE NOT EXISTS { (u)-[:TRACKED_BY]->() } RETURN u.summaryWhat may be written — anything else is refused before the query runs, with the rule it broke:
| Write | Allowed when |
|---|---|
CREATE / MERGE a node |
every label on it is a projected type |
CREATE / MERGE a relationship |
it is declared under relationships: on a projected type (§7.8), so one end is always projected — never an edge between two stored nodes |
SET / REMOVE |
on elements this run created |
DELETE |
of elements this run created; never of stored ones |
- World types are never created.
CREATE (:CustomerAccount …)is refused in a query exactly asai.fromTextresolves a world type instead of inventing one. - Declared properties only. A property set on a projected node must be declared on its type; a
required property left
nullraises aPROJECTION_INCOMPLETEwarning naming the row, rather than being admitted silently. MERGEon a projected type is keyed construction — one node per distinct key, how a query collapses duplicates.- Relationship ends are checked by type, and a variable is typed by where it came from.
tcabove has no label written, but it was unwound fromrelevant(c, …)overSupportCasenodes, so it is aSupportCaseandTRACKED_BYis admitted. A variable fed from a parameter or a literal list has no such origin and is refused; write the label (MATCH (x:SupportCase)) if you need one. - Use fresh names across stages. A name dropped by a
WITHand bound again by a laterMATCH, or reused acrossCALL {}bodies, is refused (§4) — henceuntrackedandt2above. - A model call may not feed the rest of a statement from what that statement wrote. A judgement or
reduction written after a
CREATE, whose result a later clause reads, is refused rather than run early. One whose result is only returned at the end is computed after the statement and may read what it made. Elements projected byai.fromTextare not “written” in this sense — the query above judges stored cases and links projected issues to them.
A caller need not write the steps at all: given only the final MATCH … RETURN, a planner chooses them from
the world’s views and rules and compiles them into exactly this shape of unit subqueries (§16).

