Skip to content

Commit

Permalink
Added new graph methods for vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
dlozina-macrometa committed Mar 23, 2023
1 parent d812022 commit bae6a6a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 11 deletions.
92 changes: 86 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ export class C8Client extends Fabric {
return streamApp.activateStreamApplication(active);
}

//************
// Graphs Methods
//------------ Graph ----------
getGraphs(): Promise<Graph[]> {
return this.graphs();
}
Expand Down Expand Up @@ -549,6 +548,22 @@ export class C8Client extends Fabric {
return graph.addEdgeDefinition(definition);
}

removeEdgeDefinition(graphName: string, edgeCollectionName: string) {
const graph = this.graph(graphName);
return graph.removeEdgeDefinition(edgeCollectionName);
}

getEdge(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
opts: any = {}
) {
const graph = this.graph(graphName);
const graphEdgeCollection = graph.edgeCollection(collectionName);
return graphEdgeCollection.document(documentHandle, opts);
}

updateEdge(
graphName: string,
collectionName: string,
Expand Down Expand Up @@ -617,18 +632,83 @@ export class C8Client extends Fabric {
return graph.listVertexCollections();
}

addVertexToCollection(
async addVertexCollection(graphName: string, collectionName: string) {
const graph = this.graph(graphName);
return graph.addVertexCollection(collectionName);
}

async removeVertexCollection(
graphName: string,
collectionName: string,
dropCollection: boolean = false
) {
const graph = this.graph(graphName);
return graph.removeVertexCollection(collectionName, dropCollection);
}

addVertexToVertexCollection(
graphName: string,
collectionName: string,
properties: any = {},
returnNew: boolean = false
) {
const graph = this.graph(graphName);
return graph.addVertexToCollection(collectionName, properties, returnNew);
return graph.addVertexToVertexCollection(
collectionName,
properties,
returnNew
);
}

removeVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph.vertexCollection(collectionName).remove(documentHandle, opts);
}

getVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph
.vertexCollection(collectionName)
.document(documentHandle, opts);
}

updateVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
newValue: any,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph
.vertexCollection(collectionName)
.update(documentHandle, newValue, opts);
}

replaceVertexFromVertexCollection(
graphName: string,
collectionName: string,
documentHandle: DocumentHandle,
newValue: any,
opts: any = {}
) {
const graph = this.graph(graphName);
return graph
.vertexCollection(collectionName)
.replace(documentHandle, newValue, opts);
}

//************
// Users Methods
//------------ User ----------
hasUser(userName: string) {
const user = this.user(userName);
return user.hasUser();
Expand Down
6 changes: 1 addition & 5 deletions src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,7 @@ export class Graph {
);
}

//todo New Edge Endpoints

// todo Add Vertex to given collection
addVertexToCollection(
addVertexToVertexCollection(
collectionName: string,
properties: any = {},
returnNew: boolean = false
Expand All @@ -479,7 +476,6 @@ export class Graph {
);
}

// todo Add new Edge to given collection
addEdgeToEdgeCollection(
edgeCollectionName: string,
properties: any = {},
Expand Down

0 comments on commit bae6a6a

Please sign in to comment.