Skip to content

Commit ab13d4e

Browse files
New Components - neo4j_auradb (#15848)
* neo4j_auradb init * [Components] neo4j_auradb #15828 Sources - New Node - New Relationship - New Query Result Actions - Create Node - Create Relationship - Run Query * pnpm update * remove unnecessary fields on source base file * Update components/neo4j_auradb/actions/create-node/create-node.mjs Co-authored-by: michelle0927 <[email protected]> * some adjusts * [ACTION] Calendly - List User Availability Schedules #15214 Actions - List User Availability Schedules * some adjusts * remove console.log * some adjusts * some adjusts * error validation added * pnpm update * remove wrong file --------- Co-authored-by: michelle0927 <[email protected]>
1 parent b6e4ac2 commit ab13d4e

File tree

13 files changed

+505
-6
lines changed

13 files changed

+505
-6
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import app from "../../neo4j_auradb.app.mjs";
4+
5+
export default {
6+
key: "neo4j_auradb-create-node",
7+
name: "Create Node",
8+
description: "Creates a new node in the Neo4j AuraDB instance. [See the documentation](https://neo4j.com/docs/query-api/current/query/)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
nodeLabel: {
14+
type: "string",
15+
label: "Node Label",
16+
description: "The label of the node to filter events for new node creation.",
17+
},
18+
nodeProperties: {
19+
type: "object",
20+
label: "Create Node Properties",
21+
description: "An object representing the properties of the node to create.",
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.createNode({
26+
$,
27+
label: this.nodeLabel,
28+
properties: parseObject(this.nodeProperties),
29+
});
30+
31+
if (response.errors) {
32+
throw new ConfigurationError(response.errors[0].message);
33+
}
34+
35+
const elementId = response.data?.values?.[0]?.[0]?.elementId;
36+
$.export("$summary", elementId
37+
? `Created node with id ${elementId}`
38+
: "Node created successfully");
39+
return response;
40+
},
41+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import app from "../../neo4j_auradb.app.mjs";
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](https://neo4j.com/docs/query-api/current/query/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
relationshipType: {
13+
type: "string",
14+
label: "Create Relationship Type",
15+
description: "The name of the relationship to create.",
16+
},
17+
startNode: {
18+
type: "object",
19+
label: "Start Node Identifier",
20+
description: "An object containing any fields used to identify the start node.",
21+
},
22+
endNode: {
23+
type: "object",
24+
label: "End Node Identifier",
25+
description: "An object containing any fields used to identify the end node.",
26+
},
27+
relationshipProperties: {
28+
type: "object",
29+
label: "Create Relationship Properties",
30+
description: "An object representing the properties of the relationship to create.",
31+
optional: true,
32+
},
33+
},
34+
async run({ $ }) {
35+
const response = await this.app.createRelationship({
36+
$,
37+
relationshipType: this.relationshipType,
38+
startNode: parseObject(this.startNode),
39+
endNode: parseObject(this.endNode),
40+
relationshipProperties: parseObject(this.relationshipProperties),
41+
});
42+
$.export(
43+
"$summary",
44+
`Created relationship '${this.relationshipType}' between nodes`,
45+
);
46+
return response;
47+
},
48+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import app from "../../neo4j_auradb.app.mjs";
2+
3+
export default {
4+
key: "neo4j_auradb-run-query",
5+
name: "Run Cypher Query",
6+
description: "Executes a Cypher query against the Neo4j AuraDB instance. [See the documentation](https://neo4j.com/docs/query-api/current/query/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
cypherQuery: {
12+
type: "string",
13+
label: "Execute Cypher Query",
14+
description: "A valid Cypher query to execute against the Neo4j AuraDB instance.",
15+
},
16+
},
17+
async run({ $ }) {
18+
const response = await this.app.executeCypherQuery({
19+
$,
20+
cypherQuery: this.cypherQuery,
21+
});
22+
$.export("$summary", "Executed Cypher query successfully");
23+
return response;
24+
},
25+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const LIMIT = 100;
2+
3+
export const ORDER_TYPE_OPTIONS = [
4+
{
5+
label: "DateTime",
6+
value: "datetime",
7+
},
8+
{
9+
label: "Sequential (Integer)",
10+
value: "sequential",
11+
},
12+
{
13+
label: "Other",
14+
value: "other",
15+
},
16+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,109 @@
1+
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "neo4j_auradb",
47
propDefinitions: {},
58
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
9+
_baseUrl() {
10+
return `${this.$auth.api_url}`;
11+
},
12+
_auth() {
13+
return {
14+
username: `${this.$auth.username}`,
15+
password: `${this.$auth.password}`,
16+
};
17+
},
18+
_makeRequest({
19+
$ = this, path = "", ...opts
20+
}) {
21+
return axios($, {
22+
url: this._baseUrl() + path,
23+
auth: this._auth(),
24+
...opts,
25+
});
26+
},
27+
createNode({
28+
label, properties, ...opts
29+
}) {
30+
const cypher = `CREATE (n:${label} $properties) RETURN n AS Node`;
31+
return this._makeRequest({
32+
method: "POST",
33+
data: {
34+
statement: cypher,
35+
parameters: {
36+
properties,
37+
},
38+
},
39+
...opts,
40+
});
41+
},
42+
createRelationship({
43+
relationshipType,
44+
startNode,
45+
endNode,
46+
relationshipProperties = {},
47+
...opts
48+
}) {
49+
const stringStartNode = JSON.stringify(startNode).replace(/"[^"]*":/g, (match) => match.replace(/"/g, ""));
50+
const stringEndNode = JSON.stringify(endNode).replace(/"[^"]*":/g, (match) => match.replace(/"/g, ""));
51+
const cypher = `
52+
MATCH (a ${stringStartNode})
53+
MATCH (b ${stringEndNode})
54+
CREATE (a)-[r:${relationshipType} $properties]->(b)
55+
RETURN r
56+
`;
57+
return this._makeRequest({
58+
method: "POST",
59+
data: {
60+
statement: cypher,
61+
parameters: {
62+
startNode,
63+
endNode,
64+
properties: relationshipProperties,
65+
},
66+
},
67+
...opts,
68+
});
69+
},
70+
executeCypherQuery({
71+
cypherQuery, ...opts
72+
}) {
73+
return this._makeRequest({
74+
method: "POST",
75+
data: {
76+
statement: cypherQuery,
77+
},
78+
...opts,
79+
});
80+
},
81+
async *paginate({
82+
query, maxResults = null,
83+
}) {
84+
let hasMore = false;
85+
let count = 0;
86+
let page = 0;
87+
let cypherQuery = "";
88+
89+
do {
90+
cypherQuery = `${query} SKIP ${LIMIT * page} LIMIT ${LIMIT}`;
91+
page++;
92+
93+
const { data: { values } } = await this.executeCypherQuery({
94+
cypherQuery,
95+
});
96+
for (const d of values) {
97+
yield d[0];
98+
99+
if (maxResults && ++count === maxResults) {
100+
return count;
101+
}
102+
}
103+
104+
hasMore = values.length;
105+
106+
} while (hasMore);
9107
},
10108
},
11109
};

components/neo4j_auradb/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/neo4j_auradb",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Neo4j AuraDB Components",
55
"main": "neo4j_auradb.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)