Skip to content

Commit

Permalink
QueryEngine as a type (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcginnes authored Dec 12, 2024
1 parent 1cca0dc commit bf0d0e8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Schema } from "../ConfigurationProvider";
import { MutableSnapshot } from "recoil";
import { schemaAtom } from "./schema";
import { ConnectionConfig } from "@shared/types";
import { QueryEngine } from "@shared/types";

describe("useDisplayEdgeFromEdge", () => {
it("should keep the same ID", () => {
Expand Down Expand Up @@ -226,10 +226,7 @@ describe("useDisplayEdgeFromEdge", () => {
};
}

function withSchemaAndConnection(
schema: Schema,
queryEngine: ConnectionConfig["queryEngine"]
) {
function withSchemaAndConnection(schema: Schema, queryEngine: QueryEngine) {
const config = createRandomRawConfiguration();
config.connection!.queryEngine = queryEngine;
return (snapshot: MutableSnapshot) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { DisplayAttribute } from "./displayAttribute";
import { createRandomDate } from "@shared/utils/testing";
import { MISSING_DISPLAY_VALUE } from "@/utils/constants";
import { mapToDisplayVertexTypeConfig } from "./displayTypeConfigs";
import { ConnectionConfig } from "@shared/types";
import { QueryEngine } from "@shared/types";

describe("useDisplayVertexFromVertex", () => {
it("should keep the same ID", () => {
Expand Down Expand Up @@ -252,10 +252,7 @@ describe("useDisplayVertexFromVertex", () => {
};
}

function withSchemaAndConnection(
schema: Schema,
queryEngine: ConnectionConfig["queryEngine"]
) {
function withSchemaAndConnection(schema: Schema, queryEngine: QueryEngine) {
const config = createRandomRawConfiguration();
config.connection!.queryEngine = queryEngine;
return (snapshot: MutableSnapshot) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InfoTooltip, TextArea } from "@/components";
import Button from "@/components/Button";
import Input from "@/components/Input";
import Select from "@/components/Select";
import { ConnectionConfig } from "@shared/types";
import { ConnectionConfig, QueryEngine } from "@shared/types";
import {
ConfigurationContextProps,
RawConfiguration,
Expand All @@ -28,7 +28,7 @@ import { Checkbox, Label } from "@/components/radix";
type ConnectionForm = {
name?: string;
url?: string;
queryEngine?: "gremlin" | "sparql" | "openCypher";
queryEngine?: QueryEngine;
proxyConnection?: boolean;
graphDbUrl?: string;
awsAuthEnabled?: boolean;
Expand All @@ -42,7 +42,7 @@ type ConnectionForm = {

export const CONNECTIONS_OP: {
label: string;
value: NonNullable<ConnectionConfig["queryEngine"]>;
value: QueryEngine;
}[] = [
{ label: "Gremlin - PG (Property Graph)", value: "gremlin" },
{ label: "OpenCypher - PG (Property Graph)", value: "openCypher" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useKeywordSearch from "./useKeywordSearch";
import { ConnectionConfig } from "@shared/types";
import { QueryEngine } from "@shared/types";
import { createRandomSchema, renderHookWithRecoilRoot } from "@/utils/testing";
import { createRandomRawConfiguration } from "@/utils/testing";
import {
Expand All @@ -17,9 +17,7 @@ vi.mock("./useKeywordSearchQuery", () => ({
}),
}));

function initializeConfigWithQueryEngine(
queryEngine: ConnectionConfig["queryEngine"]
) {
function initializeConfigWithQueryEngine(queryEngine: QueryEngine) {
return (snapshot: MutableSnapshot) => {
// Create config and setup schema
const config = createRandomRawConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EdgeTypeConfig,
VertexTypeConfig,
} from "@/core";
import { queryEngineOptions } from "@shared/types";

const isValidHttpUrl = (str: string) => {
let url;
Expand Down Expand Up @@ -60,7 +61,7 @@ const isValidConfigurationFile = (
!data.connection.url ||
!data.connection.queryEngine ||
!isValidHttpUrl(data.connection.url) ||
!["gremlin", "sparql", "openCypher"].includes(data.connection.queryEngine)
!queryEngineOptions.includes(data.connection.queryEngine)
) {
return false;
}
Expand Down
7 changes: 2 additions & 5 deletions packages/graph-explorer/src/utils/testing/randomData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "@/core/StateProvider/userPreferences";
import { toNodeMap } from "@/core/StateProvider/nodes";
import { toEdgeMap } from "@/core/StateProvider/edges";
import { queryEngineOptions } from "@shared/types";

/*
Expand Down Expand Up @@ -207,11 +208,7 @@ export function createRandomRawConfiguration(): RawConfiguration {
const serviceType = randomlyUndefined(
pickRandomElement(["neptune-db", "neptune-graph"] as const)
);
const queryEngine = pickRandomElement([
"gremlin",
"openCypher",
"sparql",
] as const);
const queryEngine = pickRandomElement([...queryEngineOptions]);

return {
id: createRandomName("id"),
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const queryEngineOptions = ["gremlin", "sparql", "openCypher"] as const;
export type QueryEngine = (typeof queryEngineOptions)[number];

export type ConnectionConfig = {
/**
* Base URL to access to the database through HTTPs endpoints
Expand All @@ -7,7 +10,7 @@ export type ConnectionConfig = {
* Choose between gremlin or sparQL engines.
* By default, it uses gremlin
*/
queryEngine?: "gremlin" | "sparql" | "openCypher";
queryEngine?: QueryEngine;
/**
* If the service is Neptune,
* all requests should be sent through the nodejs proxy-server.
Expand Down

0 comments on commit bf0d0e8

Please sign in to comment.