Skip to content

Commit 7b74832

Browse files
authored
Merge pull request #206 from FalkorDB/staging
Staging
2 parents d5e9028 + 9a72748 commit 7b74832

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6371
-3112
lines changed

.env.local.template

Lines changed: 0 additions & 6 deletions
This file was deleted.

.github/workflows/playwright.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, staging ]
5+
pull_request:
6+
branches: [ main, staging ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
services:
12+
falkordb:
13+
image: falkordb/falkordb:latest
14+
ports:
15+
- 6379:6379
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: lts/*
21+
- name: Install dependencies
22+
run: npm ci
23+
- name: Install Playwright Browsers
24+
run: npx playwright install --with-deps
25+
- name: Set up environment variables and run tests
26+
env:
27+
FALKORDB_URL: ${{ secrets.FALKORDB_URL }}
28+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
29+
SECRET_TOKEN: ${{ secrets.SECRET_TOKEN }}
30+
NEXT_PUBLIC_MODE: UNLIMITED
31+
BACKEND_URL: ${{ secrets.BACKEND_URL }}
32+
run: |
33+
npm install
34+
npm run build
35+
NEXTAUTH_SECRET=SECRET npm start & npx playwright test --reporter=dot,list
36+
- uses: actions/upload-artifact@v4
37+
if: ${{ !cancelled() }}
38+
with:
39+
name: playwright-report
40+
path: playwright-report/
41+
retention-days: 30

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ next-env.d.ts
3737

3838

3939
# vscode
40-
/.vscode/
40+
/.vscode/
41+
node_modules/
42+
/test-results/
43+
/playwright-report/
44+
/blob-report/
45+
/playwright/.cache/

app/api/chat/[graph]/route.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { NextRequest, NextResponse } from "next/server"
2+
import { getEnvVariables } from "../../utils"
3+
4+
5+
export async function POST(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {
6+
7+
const repo = (await params).graph
8+
const msg = request.nextUrl.searchParams.get('msg')
9+
10+
try {
11+
12+
if (!msg) {
13+
throw new Error("Message parameter is required")
14+
}
15+
16+
const { url, token } = getEnvVariables()
17+
18+
const result = await fetch(`${url}/chat`, {
19+
method: 'POST',
20+
body: JSON.stringify({ repo, msg }),
21+
headers: {
22+
"Authorization": token,
23+
"Content-Type": 'application/json'
24+
},
25+
cache: 'no-store'
26+
})
27+
28+
if (!result.ok) {
29+
throw new Error(await result.text())
30+
}
31+
32+
const json = await result.json()
33+
34+
return NextResponse.json({ result: json }, { status: 200 })
35+
} catch (err) {
36+
console.error(err)
37+
return NextResponse.json((err as Error).message, { status: 400 })
38+
}
39+
}
Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1-
import { FalkorDB, Graph } from "falkordb";
1+
import { getEnvVariables } from "@/app/api/utils";
22
import { NextRequest, NextResponse } from "next/server";
33

4-
export async function GET(request: NextRequest, { params }: { params: { graph: string, node: string } }) {
5-
6-
const nodeId = parseInt(params.node);
7-
const graphId = params.graph;
4+
export async function POST(request: NextRequest, { params }: { params: Promise<{ graph: string, node: string }> }) {
85

9-
const db = await FalkorDB.connect({url: process.env.FALKORDB_URL || 'falkor://localhost:6379',});
10-
const graph = db.selectGraph(graphId);
6+
const p = await params;
117

12-
// Get node's neighbors
13-
const q_params = {nodeId: nodeId};
14-
const query = `MATCH (src)-[e]-(n)
15-
WHERE ID(src) = $nodeId
16-
RETURN collect(distinct { label:labels(n)[0], id:ID(n), name: n.name } ) as nodes,
17-
collect( { src: ID(startNode(e)), id: ID(e), dest: ID(endNode(e)), type: type(e) } ) as edges`;
8+
const repo = p.graph;
9+
const src = Number(p.node);
10+
const dest = Number(request.nextUrl.searchParams.get('targetId'))
1811

19-
let res: any = await graph.query(query, { params: q_params });
20-
let nodes = res.data[0]['nodes'];
21-
let edges = res.data[0]['edges'];
12+
try {
2213

23-
return NextResponse.json({ id: graphId, nodes: nodes, edges: edges }, { status: 200 })
14+
if (!dest) {
15+
throw new Error("targetId is required");
16+
}
17+
18+
const { url, token } = getEnvVariables()
19+
20+
const result = await fetch(`${url}/find_paths`, {
21+
method: 'POST',
22+
headers: {
23+
"Authorization": token,
24+
'Content-Type': 'application/json'
25+
},
26+
body: JSON.stringify({
27+
repo,
28+
src,
29+
dest
30+
}),
31+
cache: 'no-store'
32+
})
33+
34+
if (!result.ok) {
35+
throw new Error(await result.text())
36+
}
37+
38+
const json = await result.json()
39+
40+
return NextResponse.json({ result: json }, { status: 200 })
41+
} catch (err) {
42+
console.error(err)
43+
return NextResponse.json((err as Error).message, { status: 400 })
44+
}
2445
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { getEnvVariables } from "@/app/api/utils";
2+
import { NextRequest, NextResponse } from "next/server";
3+
4+
export async function GET(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {
5+
6+
const repo = (await params).graph
7+
8+
try {
9+
10+
const { url, token } = getEnvVariables()
11+
12+
const result = await fetch(`${url}/list_commits`, {
13+
method: 'POST',
14+
body: JSON.stringify({ repo }),
15+
headers: {
16+
"Authorization": token,
17+
"Content-Type": 'application/json'
18+
},
19+
cache: 'no-store'
20+
})
21+
22+
if (!result.ok) {
23+
throw new Error(await result.text())
24+
}
25+
26+
const json = await result.json()
27+
28+
return NextResponse.json({ result: json }, { status: 200 })
29+
} catch (err) {
30+
console.error(err)
31+
return NextResponse.json((err as Error).message, { status: 400 })
32+
}
33+
}
34+
35+
export async function POST(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {
36+
37+
}

app/api/repo/[graph]/info/route.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { getEnvVariables } from "@/app/api/utils";
3+
4+
export async function GET(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {
5+
6+
const repo = (await params).graph
7+
8+
try {
9+
10+
const { url, token } = getEnvVariables();
11+
12+
const result = await fetch(`${url}/repo_info`, {
13+
method: 'POST',
14+
body: JSON.stringify({ repo }),
15+
headers: {
16+
"Authorization": token,
17+
"Content-Type": 'application/json'
18+
},
19+
cache: 'no-store'
20+
})
21+
22+
if (!result.ok) {
23+
throw new Error(await result.text())
24+
}
25+
26+
const json = await result.json()
27+
28+
return NextResponse.json({ result: json }, { status: 200 })
29+
} catch (err) {
30+
console.error(err)
31+
return NextResponse.json((err as Error).message, { status: 400 })
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { getEnvVariables } from "@/app/api/utils";
3+
4+
export async function POST(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {
5+
6+
const repo = (await params).graph;
7+
const node_ids = (await request.json()).nodeIds.map((id: string) => Number(id));
8+
9+
try {
10+
11+
const { url, token } = getEnvVariables();
12+
13+
if (node_ids.length === 0) {
14+
throw new Error("nodeIds is required");
15+
}
16+
17+
const result = await fetch(`${url}/get_neighbors`, {
18+
method: 'POST',
19+
body: JSON.stringify({ node_ids, repo }),
20+
headers: {
21+
"Content-Type": 'application/json',
22+
"Authorization": token,
23+
},
24+
cache: 'no-store'
25+
})
26+
27+
const json = await result.json()
28+
29+
return NextResponse.json({ result: json }, { status: 200 })
30+
} catch (err) {
31+
console.error(err)
32+
return NextResponse.json((err as Error).message, { status: 400 })
33+
}
34+
}

0 commit comments

Comments
 (0)