Skip to content

Commit 96e842e

Browse files
committed
feat: protocol
1 parent 22e1c8f commit 96e842e

File tree

6 files changed

+1159
-82
lines changed

6 files changed

+1159
-82
lines changed

infrastructure/evault-core/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
"@types/node": "^22.13.10",
1515
"dotenv": "^16.5.0",
1616
"testcontainers": "^10.24.2",
17+
"tsx": "^4.19.3",
1718
"typescript": "^5.8.3",
1819
"uuid": "^11.1.0",
1920
"vitest": "^3.0.9"
2021
},
2122
"dependencies": {
2223
"@testcontainers/neo4j": "^10.24.2",
24+
"graphql": "^16.10.0",
25+
"graphql-type-json": "^0.3.2",
26+
"graphql-voyager": "^2.1.0",
27+
"graphql-yoga": "^5.13.4",
2328
"json-schema": "^0.4.0",
2429
"neo4j-driver": "^5.28.1",
2530
"w3id": "workspace:*"

infrastructure/evault-core/src/db/db.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import neo4j, { Driver } from "neo4j-driver";
1+
import { Driver } from "neo4j-driver";
22
import { W3IDBuilder } from "w3id";
33
import { serializeValue, deserializeValue } from "./schema";
44
import {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import neo4j from "neo4j-driver";
2+
import { DbService } from "./db/db.service";
3+
import { GraphQLServer } from "./protocol/graphql-server";
4+
5+
async function startEVault() {
6+
const uri = `bolt://localhost:7687`;
7+
const driver = neo4j.driver(uri, neo4j.auth.basic("neo4j", "testpass"));
8+
const dbService = new DbService(driver);
9+
new GraphQLServer(dbService);
10+
}
11+
12+
startEVault();
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { createSchema, createYoga } from "graphql-yoga";
2+
import { createServer } from "http";
3+
import { typeDefs } from "./typedefs";
4+
import { DbService } from "../db/db.service";
5+
import { renderVoyagerPage } from "graphql-voyager/middleware";
6+
7+
export class GraphQLServer {
8+
private db: DbService;
9+
10+
constructor(db: DbService) {
11+
this.db = db;
12+
this.instantiateServer();
13+
}
14+
15+
private instantiateServer() {
16+
const resolvers = {
17+
JSON: require("graphql-type-json"),
18+
19+
Query: {
20+
getMetaEnvelopeById: (_: any, { id }: { id: string }) =>
21+
this.db.findMetaEnvelopeById(id),
22+
findMetaEnvelopesByOntology: (
23+
_: any,
24+
{ ontology }: { ontology: string },
25+
) => this.db.findMetaEnvelopesByOntology(ontology),
26+
searchMetaEnvelopes: (
27+
_: any,
28+
{ ontology, term }: { ontology: string; term: string },
29+
) => this.db.findMetaEnvelopesBySearchTerm(ontology, term),
30+
getAllEnvelopes: () => this.db.getAllEnvelopes(),
31+
},
32+
33+
Mutation: {
34+
storeMetaEnvelope: async (
35+
_: any,
36+
{
37+
input,
38+
}: {
39+
input: {
40+
ontology: string;
41+
payload: any;
42+
acl: string[];
43+
};
44+
},
45+
) => {
46+
return await this.db.storeMetaEnvelope(
47+
{
48+
ontology: input.ontology,
49+
payload: input.payload,
50+
acl: input.acl,
51+
},
52+
input.acl,
53+
);
54+
},
55+
deleteMetaEnvelope: async (_: any, { id }: { id: string }) => {
56+
await this.db.deleteMetaEnvelope(id);
57+
return true;
58+
},
59+
updateEnvelopeValue: async (
60+
_: any,
61+
{
62+
envelopeId,
63+
newValue,
64+
}: { envelopeId: string; newValue: any },
65+
) => {
66+
await this.db.updateEnvelopeValue(envelopeId, newValue);
67+
return true;
68+
},
69+
},
70+
};
71+
72+
const schema = createSchema({ typeDefs, resolvers });
73+
const yoga = createYoga({ schema });
74+
const server = createServer((req, res) => {
75+
if (req.url === "/voyager") {
76+
res.writeHead(200, { "Content-Type": "text/html" });
77+
res.end(
78+
renderVoyagerPage({
79+
endpointUrl: "/graphql",
80+
}),
81+
);
82+
} else {
83+
yoga(req, res);
84+
}
85+
});
86+
87+
server.listen(4000, () => {
88+
console.log("🚀 GraphQL at http://localhost:4000/graphql");
89+
console.log("🛰️ Voyager at http://localhost:4000/voyager");
90+
});
91+
}
92+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// GraphQL Schema Definition
2+
export const typeDefs = /* GraphQL */ `
3+
scalar JSON
4+
5+
type Envelope {
6+
id: String!
7+
ontology: String!
8+
value: JSON
9+
valueType: String
10+
}
11+
12+
type MetaEnvelope {
13+
id: String!
14+
ontology: String!
15+
acl: [String!]!
16+
envelopes: [Envelope!]!
17+
parsed: JSON
18+
}
19+
20+
type StoreMetaEnvelopeResult {
21+
metaEnvelope: MetaEnvelope!
22+
envelopes: [Envelope!]!
23+
}
24+
25+
type Query {
26+
getMetaEnvelopeById(id: String!): MetaEnvelope
27+
findMetaEnvelopesByOntology(ontology: String!): [String!]!
28+
searchMetaEnvelopes(ontology: String!, term: String!): [MetaEnvelope!]!
29+
getAllEnvelopes: [Envelope!]!
30+
}
31+
32+
input MetaEnvelopeInput {
33+
ontology: String!
34+
payload: JSON!
35+
acl: [String!]!
36+
}
37+
38+
type Mutation {
39+
storeMetaEnvelope(input: MetaEnvelopeInput!): StoreMetaEnvelopeResult!
40+
deleteMetaEnvelope(id: String!): Boolean!
41+
updateEnvelopeValue(envelopeId: String!, newValue: JSON!): Boolean!
42+
}
43+
`;

0 commit comments

Comments
 (0)