@@ -59,74 +59,8 @@ async def get_neo4j_schema() -> list[types.TextContent]:
5959 """
6060
6161 get_schema_query = """
62- CALL apoc.meta.data()
63- YIELD label, property, type, other, unique, index, elementType
64-
65- // 1) collect all rows
66- WITH collect({label:label,
67- property:property,
68- type:type,
69- other:other,
70- unique:unique,
71- index:index,
72- elementType:elementType}) AS meta
73-
74- // 2) extract each node‐label exactly once
75- WITH meta,
76- apoc.coll.toSet([
77- row IN meta
78- WHERE row.elementType='node'
79- AND NOT row.label STARTS WITH '_'
80- | row.label
81- ]) AS labels
82-
83- UNWIND labels AS label
84-
85- // 3) build node attributes
86- WITH meta, label,
87- [row IN meta
88- WHERE row.elementType='node'
89- AND row.label = label
90- AND row.type <> 'RELATIONSHIP'
91- | [ row.property,
92- row.type
93- + CASE WHEN row.unique THEN ' unique' ELSE '' END
94- + CASE WHEN row.index THEN ' indexed' ELSE '' END
95- ]
96- ] AS attributes,
97-
98- // 4) collect the outgoing‐rel “stubs”
99- [row IN meta
100- WHERE row.elementType='node'
101- AND row.label = label
102- AND row.type = 'RELATIONSHIP'
103- | row
104- ] AS relRows
105-
106- // 5) for each rel stub, look up its target and its own props
107- WITH label, attributes,
108- [ r IN relRows |
109- [ r.property,
110- {
111- target: head(r.other),
112- properties: apoc.map.fromPairs(
113- [ rr IN meta
114- WHERE rr.elementType = 'relationship'
115- AND rr.label = r.property
116- AND rr.property <> '...' // filter out any spurious meta-rows if needed
117- | [ rr.property, rr.type ]
118- ]
119- )
120- }
121- ]
122- ] AS relationships
123-
124- RETURN
125- label,
126- apoc.map.fromPairs(attributes) AS attributes,
127- apoc.map.fromPairs(relationships) AS relationships;
128-
129- """
62+ CALL apoc.meta.schema();
63+ """
13064
13165 try :
13266 async with neo4j_driver .session (database = database ) as session :
0 commit comments