From abdb822387f20717e2b49200df0327e7e137d0f9 Mon Sep 17 00:00:00 2001 From: Kris McGinnes Date: Fri, 10 May 2024 15:44:42 -0500 Subject: [PATCH] Simplify file structure --- .../src/connector/gremlin/useGremlin.ts | 2 +- .../src/connector/openCypher/useOpenCypher.ts | 2 +- .../src/connector/sparql/useSPARQL.ts | 2 +- .../src/connector/useGEFetchTypes.ts | 24 ++++++++++++++ .../src/core/ConnectorProvider/types.ts | 31 ------------------- .../core/{ConnectorProvider => }/connector.ts | 12 +++---- .../graph-explorer/src/hooks/useExpandNode.ts | 2 +- .../graph-explorer/src/hooks/useFetchNode.ts | 2 +- .../graph-explorer/src/hooks/useSchemaSync.ts | 5 +-- .../src/hooks/useUpdateVertexTypeCounts.ts | 2 +- .../KeywordSearch/useKeywordSearchQuery.ts | 2 +- .../workspaces/DataExplorer/DataExplorer.tsx | 2 +- 12 files changed, 39 insertions(+), 49 deletions(-) delete mode 100644 packages/graph-explorer/src/core/ConnectorProvider/types.ts rename packages/graph-explorer/src/core/{ConnectorProvider => }/connector.ts (81%) diff --git a/packages/graph-explorer/src/connector/gremlin/useGremlin.ts b/packages/graph-explorer/src/connector/gremlin/useGremlin.ts index fda24df52..756cdb620 100644 --- a/packages/graph-explorer/src/connector/gremlin/useGremlin.ts +++ b/packages/graph-explorer/src/connector/gremlin/useGremlin.ts @@ -7,7 +7,7 @@ import keywordSearch from "./queries/keywordSearch"; import { fetchDatabaseRequest } from "../fetchDatabaseRequest"; import { GraphSummary } from "./types"; import { v4 } from "uuid"; -import { Explorer } from "../../core/ConnectorProvider/types"; +import { Explorer } from "../useGEFetchTypes"; function _gremlinFetch(connection: ConnectionConfig, options: any) { return async (queryTemplate: string) => { diff --git a/packages/graph-explorer/src/connector/openCypher/useOpenCypher.ts b/packages/graph-explorer/src/connector/openCypher/useOpenCypher.ts index d11aa5f39..3f2c58d2a 100644 --- a/packages/graph-explorer/src/connector/openCypher/useOpenCypher.ts +++ b/packages/graph-explorer/src/connector/openCypher/useOpenCypher.ts @@ -7,7 +7,7 @@ import { GraphSummary } from "./types"; import { fetchDatabaseRequest } from "../fetchDatabaseRequest"; import { ConnectionConfig } from "../../core"; import { DEFAULT_SERVICE_TYPE } from "../../utils/constants"; -import { Explorer } from "../../core/ConnectorProvider/types"; +import { Explorer } from "../useGEFetchTypes"; function _openCypherFetch(connection: ConnectionConfig, options: any) { return async (queryTemplate: string) => { diff --git a/packages/graph-explorer/src/connector/sparql/useSPARQL.ts b/packages/graph-explorer/src/connector/sparql/useSPARQL.ts index 6e6ef2534..3075be414 100644 --- a/packages/graph-explorer/src/connector/sparql/useSPARQL.ts +++ b/packages/graph-explorer/src/connector/sparql/useSPARQL.ts @@ -1,5 +1,6 @@ import type { Criterion, + Explorer, KeywordSearchRequest, KeywordSearchResponse, NeighborsResponse, @@ -21,7 +22,6 @@ import { } from "./types"; import { ConnectionConfig } from "../../core"; import { v4 } from "uuid"; -import { Explorer } from "../../core/ConnectorProvider/types"; const replaceBlankNodeFromSearch = ( blankNodes: BlankNodesMap, diff --git a/packages/graph-explorer/src/connector/useGEFetchTypes.ts b/packages/graph-explorer/src/connector/useGEFetchTypes.ts index b3629e64c..2249ceeca 100644 --- a/packages/graph-explorer/src/connector/useGEFetchTypes.ts +++ b/packages/graph-explorer/src/connector/useGEFetchTypes.ts @@ -201,3 +201,27 @@ export type ConfigurationWithConnection = Omit< "connection" > & Required>; + +/** + * Abstracted interface to the common database queries used by + * Graph Explorer. + */ +export type Explorer = { + fetchSchema: (options?: any) => Promise; + fetchVertexCountsByType: ( + req: CountsByTypeRequest, + options?: any + ) => Promise; + fetchNeighbors: ( + req: NeighborsRequest, + options?: any + ) => Promise; + fetchNeighborsCount: ( + req: NeighborsCountRequest, + options?: any + ) => Promise; + keywordSearch: ( + req: KeywordSearchRequest, + options?: any + ) => Promise; +}; diff --git a/packages/graph-explorer/src/core/ConnectorProvider/types.ts b/packages/graph-explorer/src/core/ConnectorProvider/types.ts deleted file mode 100644 index 281ee7a40..000000000 --- a/packages/graph-explorer/src/core/ConnectorProvider/types.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - CountsByTypeRequest, - CountsByTypeResponse, - KeywordSearchRequest, - KeywordSearchResponse, - NeighborsCountRequest, - NeighborsCountResponse, - NeighborsRequest, - NeighborsResponse, - SchemaResponse, -} from "../../connector/useGEFetchTypes"; - -export type Explorer = { - fetchSchema: (options?: any) => Promise; - fetchVertexCountsByType: ( - req: CountsByTypeRequest, - options?: any - ) => Promise; - fetchNeighbors: ( - req: NeighborsRequest, - options?: any - ) => Promise; - fetchNeighborsCount: ( - req: NeighborsCountRequest, - options?: any - ) => Promise; - keywordSearch: ( - req: KeywordSearchRequest, - options?: any - ) => Promise; -}; diff --git a/packages/graph-explorer/src/core/ConnectorProvider/connector.ts b/packages/graph-explorer/src/core/connector.ts similarity index 81% rename from packages/graph-explorer/src/core/ConnectorProvider/connector.ts rename to packages/graph-explorer/src/core/connector.ts index 41102ee3b..66f5ecc35 100644 --- a/packages/graph-explorer/src/core/ConnectorProvider/connector.ts +++ b/packages/graph-explorer/src/core/connector.ts @@ -1,11 +1,11 @@ import { every, isEqual } from "lodash"; -import LoggerConnector from "../../connector/LoggerConnector"; -import { createGremlinExplorer } from "../../connector/gremlin/useGremlin"; -import { createOpenCypherExplorer } from "../../connector/openCypher/useOpenCypher"; -import { createSparqlExplorer } from "../../connector/sparql/useSPARQL"; -import { mergedConfigurationSelector } from "../StateProvider/configuration"; +import LoggerConnector from "../connector/LoggerConnector"; +import { createGremlinExplorer } from "../connector/gremlin/useGremlin"; +import { createOpenCypherExplorer } from "../connector/openCypher/useOpenCypher"; +import { createSparqlExplorer } from "../connector/sparql/useSPARQL"; +import { mergedConfigurationSelector } from "./StateProvider/configuration"; import { selector } from "recoil"; -import { equalSelector } from "../../utils/recoilState"; +import { equalSelector } from "../utils/recoilState"; /** * Active connection where the value will only change when one of the diff --git a/packages/graph-explorer/src/hooks/useExpandNode.ts b/packages/graph-explorer/src/hooks/useExpandNode.ts index a8e1eb7ba..db34cc295 100644 --- a/packages/graph-explorer/src/hooks/useExpandNode.ts +++ b/packages/graph-explorer/src/hooks/useExpandNode.ts @@ -1,7 +1,7 @@ import { useCallback } from "react"; import { useNotification } from "../components/NotificationProvider"; import type { NeighborsRequest } from "../connector/useGEFetchTypes"; -import { explorerSelector } from "../core/ConnectorProvider/connector"; +import { explorerSelector } from "../core/connector"; import useEntities from "./useEntities"; import { Vertex } from "../@types/entities"; import { useRecoilValue } from "recoil"; diff --git a/packages/graph-explorer/src/hooks/useFetchNode.ts b/packages/graph-explorer/src/hooks/useFetchNode.ts index afe6bd886..b526e5795 100644 --- a/packages/graph-explorer/src/hooks/useFetchNode.ts +++ b/packages/graph-explorer/src/hooks/useFetchNode.ts @@ -1,6 +1,6 @@ import { useCallback } from "react"; import { Vertex } from "../@types/entities"; -import { explorerSelector } from "../core/ConnectorProvider/connector"; +import { explorerSelector } from "../core/connector"; import useEntities from "./useEntities"; import { NeighborsCountRequest } from "../connector/useGEFetchTypes"; import { useRecoilValue } from "recoil"; diff --git a/packages/graph-explorer/src/hooks/useSchemaSync.ts b/packages/graph-explorer/src/hooks/useSchemaSync.ts index a91721e88..98232fa47 100644 --- a/packages/graph-explorer/src/hooks/useSchemaSync.ts +++ b/packages/graph-explorer/src/hooks/useSchemaSync.ts @@ -2,10 +2,7 @@ import { useCallback, useRef } from "react"; import { useNotification } from "../components/NotificationProvider"; import type { SchemaResponse } from "../connector/useGEFetchTypes"; import useConfiguration from "../core/ConfigurationProvider/useConfiguration"; -import { - explorerSelector, - loggerSelector, -} from "../core/ConnectorProvider/connector"; +import { explorerSelector, loggerSelector } from "../core/connector"; import usePrefixesUpdater from "./usePrefixesUpdater"; import useUpdateSchema from "./useUpdateSchema"; import { createDisplayError } from "../utils/createDisplayError"; diff --git a/packages/graph-explorer/src/hooks/useUpdateVertexTypeCounts.ts b/packages/graph-explorer/src/hooks/useUpdateVertexTypeCounts.ts index 5154737f6..7122a6910 100644 --- a/packages/graph-explorer/src/hooks/useUpdateVertexTypeCounts.ts +++ b/packages/graph-explorer/src/hooks/useUpdateVertexTypeCounts.ts @@ -1,7 +1,7 @@ import { useEffect, useMemo } from "react"; import { useQuery } from "@tanstack/react-query"; import { useConfiguration } from "../core"; -import { explorerSelector } from "../core/ConnectorProvider/connector"; +import { explorerSelector } from "../core/connector"; import useUpdateSchema from "./useUpdateSchema"; import { useRecoilValue } from "recoil"; diff --git a/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearchQuery.ts b/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearchQuery.ts index 339250225..18d05ab19 100644 --- a/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearchQuery.ts +++ b/packages/graph-explorer/src/modules/KeywordSearch/useKeywordSearchQuery.ts @@ -1,7 +1,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query"; import { useNotification } from "../../components/NotificationProvider"; import { useConfiguration } from "../../core"; -import { explorerSelector } from "../../core/ConnectorProvider/connector"; +import { explorerSelector } from "../../core/connector"; import usePrefixesUpdater from "../../hooks/usePrefixesUpdater"; import { useCallback, useEffect, useMemo } from "react"; import { createDisplayError } from "../../utils/createDisplayError"; diff --git a/packages/graph-explorer/src/workspaces/DataExplorer/DataExplorer.tsx b/packages/graph-explorer/src/workspaces/DataExplorer/DataExplorer.tsx index ec38ae7ba..aba3f2235 100644 --- a/packages/graph-explorer/src/workspaces/DataExplorer/DataExplorer.tsx +++ b/packages/graph-explorer/src/workspaces/DataExplorer/DataExplorer.tsx @@ -35,7 +35,7 @@ import { useWithTheme, withClassNamePrefix, } from "../../core"; -import { explorerSelector } from "../../core/ConnectorProvider/connector"; +import { explorerSelector } from "../../core/connector"; import { userStylingAtom, VertexPreferences,