Skip to content

Commit

Permalink
Remove idType field and Ref object types (#769)
Browse files Browse the repository at this point in the history
* Remove idType field

* Remove VertexRef and EdgeRef
  • Loading branch information
kmcginnes authored Jan 29, 2025
1 parent 825b475 commit e9809e9
Show file tree
Hide file tree
Showing 50 changed files with 204 additions and 273 deletions.
4 changes: 2 additions & 2 deletions packages/graph-explorer/src/connector/gremlin/edgeDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function edgeDetails(
request: EdgeDetailsRequest
): Promise<EdgeDetailsResponse> {
const template = query`
g.E(${idParam(request.edge.id)})
g.E(${idParam(request.edgeId)})
`;

// Fetch the vertex details
Expand All @@ -42,7 +42,7 @@ export async function edgeDetails(
const entities = mapResults(data.result.data);
const edge = entities.edges.length > 0 ? entities.edges[0] : null;
if (!edge) {
logger.warn("Edge not found", request.edge);
logger.warn("Edge not found", request.edgeId);
}

return { edge };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("Gremlin > fetchNeighbors", () => {
];

const response = await fetchNeighbors(mockGremlinFetch(), {
vertex: { id: createVertexId("2018"), idType: "string" },
vertexId: createVertexId("2018"),
vertexType: "airport",
});

Expand Down Expand Up @@ -206,7 +206,7 @@ describe("Gremlin > fetchNeighbors", () => {
];

const response = await fetchNeighbors(mockGremlinFetch(), {
vertex: { id: createVertexId("2018"), idType: "string" },
vertexId: createVertexId("2018"),
vertexType: "airport",
filterByVertexTypes: ["airport"],
filterCriteria: [{ name: "code", value: "TF", operator: "LIKE" }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createVertexId } from "@/core";
describe("Gremlin > oneHopTemplate", () => {
it("Should return a template for a simple vertex id", () => {
const template = oneHopTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
});

expect(normalize(template)).toBe(
Expand All @@ -25,7 +25,7 @@ describe("Gremlin > oneHopTemplate", () => {

it("Should return a template for a simple vertex id with number type", () => {
const template = oneHopTemplate({
vertex: { id: createVertexId(12), idType: "number" },
vertexId: createVertexId(12),
});

expect(normalize(template)).toBe(
Expand All @@ -45,7 +45,7 @@ describe("Gremlin > oneHopTemplate", () => {

it("Should return a template with an offset and limit", () => {
const template = oneHopTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
offset: 5,
limit: 5,
});
Expand All @@ -67,7 +67,7 @@ describe("Gremlin > oneHopTemplate", () => {

it("Should return a template for specific vertex type", () => {
const template = oneHopTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
filterByVertexTypes: ["country"],
offset: 5,
limit: 10,
Expand All @@ -90,7 +90,7 @@ describe("Gremlin > oneHopTemplate", () => {

it("Should return a template for multiple vertex type", () => {
const template = oneHopTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
filterByVertexTypes: ["country", "airport", "continent"],
offset: 5,
limit: 10,
Expand All @@ -113,7 +113,7 @@ describe("Gremlin > oneHopTemplate", () => {

it("Should return a template with specific filter criteria", () => {
const template = oneHopTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
filterByVertexTypes: ["country"],
filterCriteria: [
{ name: "longest", value: 10000, operator: "gte", dataType: "Number" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ function criterionTemplate(criterion: Criterion): string {
* )
*/
export default function oneHopTemplate({
vertex,
vertexId,
filterByVertexTypes = [],
edgeTypes = [],
filterCriteria = [],
limit = 0,
offset = 0,
}: Omit<NeighborsRequest, "vertexType">): string {
const idTemplate = idParam(vertex.id);
const idTemplate = idParam(vertexId);
const range = limit > 0 ? `.range(${offset}, ${offset + limit})` : "";

const vertexTypes = filterByVertexTypes.flatMap(type => type.split("::"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import globalMockFetch from "@/connector/testUtils/globalMockFetch";
import mockGremlinFetch from "@/connector/testUtils/mockGremlinFetch";
import fetchNeighborsCount from ".";
import { VertexId } from "@/core";
import { createVertexId } from "@/core";

describe("Gremlin > fetchNeighborsCount", () => {
beforeEach(globalMockFetch);

it("Should return neighbors counts for node 2018", async () => {
const response = await fetchNeighborsCount(mockGremlinFetch(), {
vertex: {
id: "123" as VertexId,
idType: "string",
},
vertexId: createVertexId("123"),
});

expect(response).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { normalizeWithNoSpace as normalize } from "@/utils/testing";
describe("Gremlin > neighborsCountTemplate", () => {
it("Should return a template for the given vertex id", () => {
const template = neighborsCountTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
});

expect(normalize(template)).toBe(
Expand All @@ -17,7 +17,7 @@ describe("Gremlin > neighborsCountTemplate", () => {

it("Should return a template for the given vertex id with number type", () => {
const template = neighborsCountTemplate({
vertex: { id: createVertexId(12), idType: "number" },
vertexId: createVertexId(12),
});

expect(normalize(template)).toBe(
Expand All @@ -29,7 +29,7 @@ describe("Gremlin > neighborsCountTemplate", () => {

it("Should return a template for the given vertex id with defined limit", () => {
const template = neighborsCountTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
limit: 20,
});

Expand All @@ -42,7 +42,7 @@ describe("Gremlin > neighborsCountTemplate", () => {

it("Should return a template for the given vertex id with no limit", () => {
const template = neighborsCountTemplate({
vertex: { id: createVertexId("12"), idType: "string" },
vertexId: createVertexId("12"),
limit: 0,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { idParam } from "../idParam";
* .group().by(label).by(count())
*/
export default function neighborsCountTemplate({
vertex,
vertexId,
limit = 0,
}: NeighborsCountRequest) {
let template = `g.V(${idParam(vertex.id)}).both()`;
let template = `g.V(${idParam(vertexId)}).both()`;

if (limit > 0) {
template += `.limit(${limit})`;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GInt64, JanusID } from "../types";

export const isJanusID = (id: any): id is JanusID => {
function isJanusID(id: any): id is JanusID {
return (
typeof id === "object" &&
"@type" in id &&
Expand All @@ -10,7 +10,7 @@ export const isJanusID = (id: any): id is JanusID => {
"relationId" in id["@value"] &&
typeof id["@value"]["relationId"] === "string"
);
};
}

export function extractRawId(id: string | GInt64 | JanusID): string | number {
if (isJanusID(id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { createEdgeId, createVertexId, type Edge } from "@/core";
import type { GEdge } from "../types";
import parseEdgePropertiesValues from "./parseEdgePropertiesValues";

import { detectIdType } from "./detectIdType";
import { extractRawId } from "./extractRawId";

const mapApiEdge = (apiEdge: GEdge): Edge => {
const isFragment = apiEdge["@value"].properties == null;
return {
entityType: "edge",
id: createEdgeId(extractRawId(apiEdge["@value"].id)),
idType: detectIdType(apiEdge["@value"].id),
type: apiEdge["@value"].label,
source: createVertexId(extractRawId(apiEdge["@value"].outV)),
sourceType: apiEdge["@value"].outVLabel,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createVertexId, type Vertex } from "@/core";
import type { GVertex } from "../types";
import { detectIdType } from "./detectIdType";
import parsePropertiesValues from "./parsePropertiesValues";
import { extractRawId } from "./extractRawId";

Expand All @@ -12,7 +11,6 @@ const mapApiVertex = (apiVertex: GVertex): Vertex => {
return {
entityType: "vertex",
id: createVertexId(extractRawId(apiVertex["@value"].id)),
idType: detectIdType(apiVertex["@value"].id),
type: vt,
types: labels,
attributes: parsePropertiesValues(apiVertex["@value"].properties ?? {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function vertexDetails(
request: VertexDetailsRequest
): Promise<VertexDetailsResponse> {
const template = query`
g.V(${idParam(request.vertex.id)})
g.V(${idParam(request.vertexId)})
`;

// Fetch the vertex details
Expand All @@ -41,7 +41,7 @@ export async function vertexDetails(
const entities = mapResults(data.result.data);
const vertex = entities.vertices.length > 0 ? entities.vertices[0] : null;
if (!vertex) {
logger.warn("Vertex not found", request.vertex);
logger.warn("Vertex not found", request.vertexId);
}

return { vertex };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export async function edgeDetails(
): Promise<EdgeDetailsResponse> {
const template = query`
MATCH ()-[edge]-()
WHERE ID(edge) = ${idParam(req.edge.id)}
WHERE ID(edge) = ${idParam(req.edgeId)}
RETURN edge, labels(startNode(edge)) as sourceLabels, labels(endNode(edge)) as targetLabels
`;
const data = await openCypherFetch<Response | ErrorResponse>(template);

if (isErrorResponse(data)) {
logger.error(
"Failed to fetch edge details",
req.edge,
req.edgeId,
data.detailedMessage
);
throw new Error(data.detailedMessage);
Expand All @@ -42,7 +42,7 @@ export async function edgeDetails(
const value = data.results[0];

if (!value) {
console.warn("Edge not found", req.edge);
console.warn("Edge not found", req.edgeId);
return { edge: null };
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { normalize } from "@/utils/testing";
import oneHopTemplate from "./oneHopTemplate";
import { VertexId } from "@/core";
import { createVertexId } from "@/core";

describe("OpenCypher > oneHopTemplate", () => {
it("Should return a template for a simple vertex id", () => {
const template = oneHopTemplate({
vertex: { id: "12" as VertexId, idType: "string" },
vertexId: createVertexId("12"),
});

expect(normalize(template)).toEqual(
Expand All @@ -25,7 +25,7 @@ describe("OpenCypher > oneHopTemplate", () => {

it("Should return a template with an offset and limit", () => {
const template = oneHopTemplate({
vertex: { id: "12" as VertexId, idType: "string" },
vertexId: createVertexId("12"),
offset: 5,
limit: 5,
});
Expand All @@ -49,7 +49,7 @@ describe("OpenCypher > oneHopTemplate", () => {

it("Should return a template for specific vertex type", () => {
const template = oneHopTemplate({
vertex: { id: "12" as VertexId, idType: "string" },
vertexId: createVertexId("12"),
filterByVertexTypes: ["country"],
offset: 5,
limit: 10,
Expand All @@ -74,7 +74,7 @@ describe("OpenCypher > oneHopTemplate", () => {

it("Should return a template for many vertex types", () => {
const template = oneHopTemplate({
vertex: { id: "12" as VertexId, idType: "string" },
vertexId: createVertexId("12"),
filterByVertexTypes: ["country", "continent", "airport", "person"],
});

Expand All @@ -95,7 +95,7 @@ describe("OpenCypher > oneHopTemplate", () => {

it("Should return a template for specific edge type", () => {
const template = oneHopTemplate({
vertex: { id: "12" as VertexId, idType: "string" },
vertexId: createVertexId("12"),
edgeTypes: ["locatedIn"],
offset: 5,
limit: 10,
Expand All @@ -120,7 +120,7 @@ describe("OpenCypher > oneHopTemplate", () => {

it("Should return a template with specific filter criteria", () => {
const template = oneHopTemplate({
vertex: { id: "12" as VertexId, idType: "string" },
vertexId: createVertexId("12"),
filterByVertexTypes: ["country"],
filterCriteria: [
{ name: "longest", value: 10000, operator: "gte", dataType: "Number" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const criterionTemplate = (criterion: Criterion): string => {
* LIMIT 10
*/
const oneHopTemplate = ({
vertex,
vertexId,
filterByVertexTypes = [],
edgeTypes = [],
filterCriteria = [],
Expand All @@ -130,7 +130,7 @@ const oneHopTemplate = ({

// Combine all the WHERE conditions
const whereConditions = [
`ID(v) = ${idParam(vertex.id)}`,
`ID(v) = ${idParam(vertexId)}`,
formattedVertexTypes,
...(filterCriteria?.map(criterionTemplate) ?? []),
]
Expand Down
Loading

0 comments on commit e9809e9

Please sign in to comment.