apache / apache/age

Call subquery

Open
#1,690 5 comments 1 reaction 0 assignees View on GitHub
enhancement override-stale
Dominant language
C
Stars
4.8k
Forks
523
Avg merge
1d 2h
Merged PRs (30d)
9

Description

Should we add [call subquery](https://neo4j.com/docs/cypher-manual/current/subqueries/call-subquery/?utm_source=Google&utm_medium=PaidSearch&utm_campaign=Evergreenutm_content=AMS-Search-SEMCE-DSA-None-SEM-SEM-NonABM&utm_term=&utm_adgroup=DSA-use-cases&gad_source=1&gclid=CjwKCAjw48-vBhBbEiwAzqrZVLKhZ3Swr9FxOtwkjpaA9BWPj8vjzbjxoapsZf0gapp3RPktxKf2BxoCnWwQAvD_BwE) to AGE? It will allow Neo4j's GraphQL library to be compatible with AGE.

**Data Setup**
```sql
SELECT * FROM cypher('xyz', $$
CREATE (:Actor{name:'Tom Hanks'})-[:ACTED_IN]->(:Movie{title:'Forrest Gump'})
$$) as (a agtype);
```

**Two uses of call subquery**

1)
```sql
SELECT * FROM ag_catalog.cypher('xyz', $$
MATCH (this:Movie)
CALL {
WITH this
MATCH (this)<-[this0:ACTED_IN]-(this1:Actor)
WITH ag_catalog.agtype_build_map('name', this1.name) AS this1
RETURN collect(this1) AS var2
}
RETURN ag_catalog.agtype_build_map('title', this.title, 'actors', var2) AS this
$$) as ("?" agtype);
```

2)
```sql
SELECT * FROM ag_catalog.cypher('xyz', $$
UNWIND $create_param0 AS create_var0
CALL {
WITH create_var0
CREATE (create_this1:Movie)
SET
create_this1.title = create_var0.title
WITH create_this1, create_var0
CALL {
WITH create_this1, create_var0
UNWIND create_var0.actors.create AS create_var2
WITH create_var2.node AS create_var3, create_var2.edge AS create_var4, create_this1
CREATE (create_this5:Actor)
SET
create_this5.name = create_var3.name
MERGE (create_this1)<-[create_this6:ACTED_IN]-(create_this5)

RETURN collect(NULL) AS create_var7
}

RETURN create_this1
}
CALL {
WITH create_this1
MATCH (create_this1)<-[create_this8:ACTED_IN]-(create_this9:Actor)
WITH ag_catalog.agtype_build_map('name', create_this9.name) AS create_this9
RETURN collect(create_this9) AS create_var10
}
RETURN collect(ag_catalog.agtype_build_map('title', create_this1.title, 'actors', create_var10)) AS data
$$,
'[ { title: 'Forrest Gump', actors: { create: [{ node: { name: "Tom Hanks" } }] } } ]' -- parameter
) as ("?" agtype);
```

**Expected output**
For both queries:
```
[
{
"title": "Forrest Gump",
"actors": [
{
"name": "Tom Hanks"
}
]
}
]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.