Skip to content

Commit c07e308

Browse files
committed
neo4j_auradb init
1 parent aa27714 commit c07e308

File tree

8 files changed

+640
-3
lines changed

8 files changed

+640
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import neo4jAuradb from "../../neo4j_auradb.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "neo4j_auradb-create-node",
6+
name: "Create Node",
7+
description: "Creates a new node in the Neo4j AuraDB instance. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
neo4jAuradb,
12+
createNodeLabel: {
13+
propDefinition: [
14+
neo4jAuradb,
15+
"createNodeLabel",
16+
],
17+
},
18+
createNodeProperties: {
19+
propDefinition: [
20+
neo4jAuradb,
21+
"createNodeProperties",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.neo4jAuradb.createNode({
27+
createNodeLabel: this.createNodeLabel,
28+
createNodeProperties: this.createNodeProperties,
29+
});
30+
31+
const node = response.results?.[0]?.data?.[0]?.row?.[0];
32+
$.export("$summary", node
33+
? `Created node with id ${node.id}`
34+
: "Node created successfully");
35+
return response;
36+
},
37+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import neo4jAuradb from "../../neo4j_auradb.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "neo4j_auradb-create-relationship",
6+
name: "Create Relationship",
7+
description: "Creates a relationship between two existing nodes. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
neo4jAuradb: {
12+
type: "app",
13+
app: "neo4j_auradb",
14+
},
15+
createRelationshipType: {
16+
propDefinition: [
17+
"neo4j_auradb",
18+
"createRelationshipType",
19+
],
20+
},
21+
createStartNode: {
22+
propDefinition: [
23+
"neo4j_auradb",
24+
"createStartNode",
25+
],
26+
},
27+
createEndNode: {
28+
propDefinition: [
29+
"neo4j_auradb",
30+
"createEndNode",
31+
],
32+
},
33+
createRelationshipProperties: {
34+
propDefinition: [
35+
"neo4j_auradb",
36+
"createRelationshipProperties",
37+
],
38+
},
39+
},
40+
async run({ $ }) {
41+
const response = await this.neo4jAuradb.createRelationship({
42+
createRelationshipType: this.createRelationshipType,
43+
createStartNode: this.createStartNode,
44+
createEndNode: this.createEndNode,
45+
createRelationshipProperties: this.createRelationshipProperties,
46+
});
47+
$.export(
48+
"$summary",
49+
`Created relationship '${this.createRelationshipType}' between nodes '${this.createStartNode}' and '${this.createEndNode}'`,
50+
);
51+
return response;
52+
},
53+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import neo4jAuradb from "../../neo4j_auradb.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "neo4j_auradb-run-query",
6+
name: "Run Cypher Query",
7+
description: "Executes a Cypher query against the Neo4j AuraDB instance. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
neo4jAuradb,
12+
executeCypherQuery: {
13+
propDefinition: [
14+
neo4jAuradb,
15+
"executeCypherQuery",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.neo4jAuradb.executeCypherQuery({
21+
executeCypherQuery: this.executeCypherQuery,
22+
});
23+
$.export("$summary", "Executed Cypher query successfully");
24+
return response;
25+
},
26+
};
Lines changed: 183 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,192 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "neo4j_auradb",
4-
propDefinitions: {},
6+
version: "0.0.{{ts}}",
7+
propDefinitions: {
8+
nodeLabel: {
9+
type: "string",
10+
label: "Node Label",
11+
description: "The label of the node to filter events for new node creation.",
12+
},
13+
relationshipType: {
14+
type: "string",
15+
label: "Relationship Type",
16+
description: "The type of the relationship to filter events for new relationship creation.",
17+
},
18+
monitorCypherQuery: {
19+
type: "string",
20+
label: "Monitor Cypher Query",
21+
description: "The Cypher query to monitor for new results.",
22+
},
23+
createNodeLabel: {
24+
type: "string",
25+
label: "Create Node Label",
26+
description: "The label of the node to create.",
27+
},
28+
createNodeProperties: {
29+
type: "string[]",
30+
label: "Create Node Properties",
31+
description: "An array of JSON strings representing the properties of the node to create.",
32+
},
33+
createRelationshipType: {
34+
type: "string",
35+
label: "Create Relationship Type",
36+
description: "The type of the relationship to create.",
37+
},
38+
createStartNode: {
39+
type: "string",
40+
label: "Start Node ID",
41+
description: "The ID of the start node for the relationship.",
42+
},
43+
createEndNode: {
44+
type: "string",
45+
label: "End Node ID",
46+
description: "The ID of the end node for the relationship.",
47+
},
48+
createRelationshipProperties: {
49+
type: "string[]",
50+
label: "Create Relationship Properties",
51+
description: "An array of JSON strings representing the properties of the relationship to create.",
52+
},
53+
executeCypherQuery: {
54+
type: "string",
55+
label: "Execute Cypher Query",
56+
description: "A valid Cypher query to execute against the Neo4j AuraDB instance.",
57+
},
58+
},
559
methods: {
6-
// this.$auth contains connected account data
760
authKeys() {
861
console.log(Object.keys(this.$auth));
962
},
63+
_baseUrl() {
64+
return `https://${this.$auth.host}/db/neo4j`;
65+
},
66+
async _makeRequest(opts = {}) {
67+
const {
68+
$ = this, method = "GET", path = "/tx/commit", headers, ...otherOpts
69+
} = opts;
70+
return axios($, {
71+
method,
72+
url: this._baseUrl() + path,
73+
headers: {
74+
...headers,
75+
Authorization: `Bearer ${this.$auth.api_token}`,
76+
},
77+
...otherOpts,
78+
});
79+
},
80+
async createNode({
81+
createNodeLabel, createNodeProperties,
82+
}) {
83+
const properties = createNodeProperties.map(JSON.parse);
84+
const cypher = `CREATE (n:${createNodeLabel} $properties) RETURN n`;
85+
const mergedProperties = Object.assign({}, ...properties);
86+
return this._makeRequest({
87+
method: "POST",
88+
data: {
89+
statements: [
90+
{
91+
statement: cypher,
92+
parameters: {
93+
properties: mergedProperties,
94+
},
95+
},
96+
],
97+
},
98+
});
99+
},
100+
async createRelationship({
101+
createRelationshipType,
102+
createStartNode,
103+
createEndNode,
104+
createRelationshipProperties,
105+
}) {
106+
const properties = createRelationshipProperties.map(JSON.parse);
107+
const cypher = `
108+
MATCH (a), (b)
109+
WHERE id(a) = $startNode AND id(b) = $endNode
110+
CREATE (a)-[r:${createRelationshipType} $properties]->(b)
111+
RETURN r
112+
`;
113+
const mergedProperties = Object.assign({}, ...properties);
114+
return this._makeRequest({
115+
method: "POST",
116+
data: {
117+
statements: [
118+
{
119+
statement: cypher,
120+
parameters: {
121+
startNode: parseInt(createStartNode, 10),
122+
endNode: parseInt(createEndNode, 10),
123+
properties: mergedProperties,
124+
},
125+
},
126+
],
127+
},
128+
});
129+
},
130+
async executeCypherQuery({ executeCypherQuery }) {
131+
return this._makeRequest({
132+
method: "POST",
133+
data: {
134+
statements: [
135+
{
136+
statement: executeCypherQuery,
137+
},
138+
],
139+
},
140+
});
141+
},
142+
async emitNewNodeEvent({ nodeLabel }) {
143+
const cypher = `MATCH (n:${nodeLabel}) RETURN n`;
144+
return this._makeRequest({
145+
method: "POST",
146+
data: {
147+
statements: [
148+
{
149+
statement: cypher,
150+
},
151+
],
152+
},
153+
});
154+
},
155+
async emitNewRelationshipEvent({ relationshipType }) {
156+
const cypher = `MATCH ()-[r:${relationshipType}]->() RETURN r`;
157+
return this._makeRequest({
158+
method: "POST",
159+
data: {
160+
statements: [
161+
{
162+
statement: cypher,
163+
},
164+
],
165+
},
166+
});
167+
},
168+
async emitCypherQueryEvent({ monitorCypherQuery }) {
169+
return this.executeCypherQuery({
170+
executeCypherQuery: monitorCypherQuery,
171+
});
172+
},
173+
async paginate(fn, ...opts) {
174+
let results = [];
175+
let moreData = true;
176+
let currentPage = 0;
177+
while (moreData) {
178+
const response = await fn({
179+
page: currentPage,
180+
...opts,
181+
});
182+
if (response.length === 0) {
183+
moreData = false;
184+
} else {
185+
results = results.concat(response);
186+
currentPage += 1;
187+
}
188+
}
189+
return results;
190+
},
10191
},
11192
};

components/neo4j_auradb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)