Skip to content

Commit 66990f3

Browse files
authored
Use a normalized connection type to reduce optionals (#922)
* Normalized connection * Fix tests * Add react compiler to babel config (for tests) * Update changelog
1 parent af22b93 commit 66990f3

File tree

11 files changed

+96
-119
lines changed

11 files changed

+96
-119
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- **Fixed** issue where a schema sync would not automatically run when a
2121
connection was changed
2222
([#919](https://github.com/aws/graph-explorer/pull/919))
23+
- **Updated** dependencies and minor refactoring of code
24+
([#922](https://github.com/aws/graph-explorer/pull/922))
2325

2426
## Release v1.15.0
2527

packages/graph-explorer/babel.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ module.exports = {
1111
"@babel/preset-react",
1212
"@babel/preset-typescript",
1313
],
14+
plugins: [
15+
[
16+
"babel-plugin-react-compiler",
17+
{
18+
target: "18", // '17' | '18' | '19'
19+
},
20+
],
21+
],
1422
};

packages/graph-explorer/src/connector/emptyExplorer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Explorer, toMappedQueryResults } from "./useGEFetchTypes";
77
export const emptyExplorer: Explorer = {
88
connection: {
99
url: "",
10+
graphDbUrl: "",
1011
queryEngine: "gremlin",
1112
proxyConnection: false,
1213
awsAuthEnabled: false,

packages/graph-explorer/src/connector/fetchDatabaseRequest.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { type ConnectionConfig } from "@shared/types";
21
import { DEFAULT_SERVICE_TYPE } from "@/utils/constants";
32
import { anySignal } from "./utils/anySignal";
4-
import { FeatureFlags } from "@/core";
3+
import { FeatureFlags, NormalizedConnection } from "@/core";
54
import { z } from "zod";
65
import { logger, NetworkError } from "@/utils";
76

@@ -57,18 +56,18 @@ async function decodeErrorSafely(response: Response): Promise<any> {
5756

5857
// Construct the request headers based on the connection settings
5958
function getAuthHeaders(
60-
connection: ConnectionConfig | undefined,
59+
connection: NormalizedConnection,
6160
featureFlags: FeatureFlags,
6261
typeHeaders: HeadersInit | undefined
6362
) {
6463
const headers: HeadersInit = {};
65-
if (connection?.proxyConnection) {
64+
if (connection.proxyConnection) {
6665
headers["graph-db-connection-url"] = connection.graphDbUrl || "";
6766
headers["db-query-logging-enabled"] = String(
6867
featureFlags.allowLoggingDbQuery
6968
);
7069
}
71-
if (connection?.awsAuthEnabled) {
70+
if (connection.awsAuthEnabled) {
7271
headers["aws-neptune-region"] = connection.awsRegion || "";
7372
headers["service-type"] = connection.serviceType || DEFAULT_SERVICE_TYPE;
7473
}
@@ -77,8 +76,8 @@ function getAuthHeaders(
7776
}
7877

7978
// Construct an AbortSignal for the fetch timeout if configured
80-
function getFetchTimeoutSignal(connection: ConnectionConfig | undefined) {
81-
if (!connection?.fetchTimeoutMs) {
79+
function getFetchTimeoutSignal(connection: NormalizedConnection) {
80+
if (!connection.fetchTimeoutMs) {
8281
return null;
8382
}
8483

@@ -90,7 +89,7 @@ function getFetchTimeoutSignal(connection: ConnectionConfig | undefined) {
9089
}
9190

9291
export async function fetchDatabaseRequest(
93-
connection: ConnectionConfig | undefined,
92+
connection: NormalizedConnection,
9493
featureFlags: FeatureFlags,
9594
uri: URL | RequestInfo,
9695
options: RequestInit

packages/graph-explorer/src/connector/gremlin/gremlinExplorer.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ConnectionConfig } from "@shared/types";
21
import fetchNeighbors from "./fetchNeighbors";
32
import fetchNeighborsCount from "./fetchNeighborsCount";
43
import fetchSchema from "./fetchSchema";
@@ -10,12 +9,12 @@ import { v4 } from "uuid";
109
import { Explorer, ExplorerRequestOptions } from "../useGEFetchTypes";
1110
import { logger } from "@/utils";
1211
import { createLoggerFromConnection } from "@/core/connector";
13-
import { FeatureFlags } from "@/core";
12+
import { FeatureFlags, NormalizedConnection } from "@/core";
1413
import { vertexDetails } from "./vertexDetails";
1514
import { edgeDetails } from "./edgeDetails";
1615

1716
function _gremlinFetch(
18-
connection: ConnectionConfig,
17+
connection: NormalizedConnection,
1918
featureFlags: FeatureFlags,
2019
options?: ExplorerRequestOptions
2120
): GremlinFetch {
@@ -45,7 +44,7 @@ function _gremlinFetch(
4544
}
4645

4746
async function fetchSummary(
48-
connection: ConnectionConfig,
47+
connection: NormalizedConnection,
4948
featureFlags: FeatureFlags,
5049
options?: RequestInit
5150
) {
@@ -69,7 +68,7 @@ async function fetchSummary(
6968
}
7069

7170
export function createGremlinExplorer(
72-
connection: ConnectionConfig,
71+
connection: NormalizedConnection,
7372
featureFlags: FeatureFlags
7473
): Explorer {
7574
const remoteLogger = createLoggerFromConnection(connection);

packages/graph-explorer/src/connector/openCypher/openCypherExplorer.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import keywordSearch from "./keywordSearch";
55
import fetchSchema from "./fetchSchema";
66
import { GraphSummary } from "./types";
77
import { fetchDatabaseRequest } from "../fetchDatabaseRequest";
8-
import { ConnectionConfig } from "@shared/types";
98
import { DEFAULT_SERVICE_TYPE } from "@/utils/constants";
109
import { Explorer, ExplorerRequestOptions } from "../useGEFetchTypes";
1110
import { env, logger } from "@/utils";
1211
import { createLoggerFromConnection } from "@/core/connector";
13-
import { FeatureFlags } from "@/core";
12+
import { FeatureFlags, NormalizedConnection } from "@/core";
1413
import { vertexDetails } from "./vertexDetails";
1514
import { edgeDetails } from "./edgeDetails";
1615

1716
function _openCypherFetch(
18-
connection: ConnectionConfig,
17+
connection: NormalizedConnection,
1918
featureFlags: FeatureFlags,
2019
options?: ExplorerRequestOptions
2120
) {
@@ -38,13 +37,13 @@ function _openCypherFetch(
3837
}
3938

4039
export function createOpenCypherExplorer(
41-
connection: ConnectionConfig,
40+
connection: NormalizedConnection,
4241
featureFlags: FeatureFlags
4342
): Explorer {
4443
const remoteLogger = createLoggerFromConnection(connection);
4544
const serviceType = connection.serviceType || DEFAULT_SERVICE_TYPE;
4645
return {
47-
connection: connection,
46+
connection,
4847
async fetchSchema(options) {
4948
remoteLogger.info("[openCypher Explorer] Fetching schema...");
5049
const summary = await fetchSummary(
@@ -108,7 +107,7 @@ export function createOpenCypherExplorer(
108107

109108
async function fetchSummary(
110109
serviceType: string,
111-
connection: ConnectionConfig,
110+
connection: NormalizedConnection,
112111
featureFlags: FeatureFlags,
113112
options?: RequestInit
114113
) {

packages/graph-explorer/src/connector/sparql/sparqlExplorer.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@ import {
1717
SPARQLKeywordSearchRequest,
1818
SPARQLNeighborsRequest,
1919
} from "./types";
20-
import { ConnectionConfig } from "@shared/types";
2120
import { v4 } from "uuid";
2221
import { env, logger } from "@/utils";
2322
import { createLoggerFromConnection } from "@/core/connector";
24-
import { FeatureFlags } from "@/core";
23+
import { FeatureFlags, NormalizedConnection } from "@/core";
2524
import { replaceBlankNodeFromNeighbors } from "./fetchNeighbors/replaceBlankNodeFromNeighbors";
2625
import { storedBlankNodeNeighborsRequest } from "./fetchNeighbors/storedBlankNodeNeighborsRequest";
2726
import { replaceBlankNodeFromSearch } from "./keywordSearch/replaceBlankNodeFromSearch";
2827
import { vertexDetails } from "./vertexDetails";
2928
import { edgeDetails } from "./edgeDetails";
3029

3130
function _sparqlFetch(
32-
connection: ConnectionConfig,
31+
connection: NormalizedConnection,
3332
featureFlags: FeatureFlags,
3433
options?: ExplorerRequestOptions
3534
) {
@@ -63,7 +62,7 @@ function _sparqlFetch(
6362
}
6463

6564
async function fetchSummary(
66-
connection: ConnectionConfig,
65+
connection: NormalizedConnection,
6766
featureFlags: FeatureFlags,
6867
options?: RequestInit
6968
) {
@@ -87,7 +86,7 @@ async function fetchSummary(
8786
}
8887

8988
export function createSparqlExplorer(
90-
connection: ConnectionConfig,
89+
connection: NormalizedConnection,
9190
featureFlags: FeatureFlags,
9291
blankNodes: BlankNodesMap
9392
): Explorer {

packages/graph-explorer/src/connector/useGEFetchTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
EdgeId,
77
Vertex,
88
VertexId,
9+
NormalizedConnection,
910
} from "@/core";
10-
import { ConnectionConfig } from "@shared/types";
1111

1212
export type QueryOptions = RequestInit & {
1313
queryId?: string;
@@ -239,7 +239,7 @@ export type EdgeDetailsResponse = {
239239
* Graph Explorer.
240240
*/
241241
export type Explorer = {
242-
connection: ConnectionConfig;
242+
connection: NormalizedConnection;
243243
fetchSchema: (options?: ExplorerRequestOptions) => Promise<SchemaResponse>;
244244
fetchVertexCountsByType: (
245245
req: CountsByTypeRequest,

packages/graph-explorer/src/core/StateProvider/configuration.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,30 @@ import {
1010
defaultEdgeTypeConfig,
1111
defaultVertexTypeConfig,
1212
mergeConfiguration,
13+
NormalizedConnection,
1314
} from "./configuration";
1415
import { RawConfiguration, VertexTypeConfig } from "../ConfigurationProvider";
1516
import { SchemaInference } from "./schema";
1617
import { UserStyling } from "./userPreferences";
1718
import { createRandomName } from "@shared/utils/testing";
1819
import { RESERVED_TYPES_PROPERTY } from "@/utils";
1920

21+
/** The default empty connection values when no value is provided. */
22+
const defaultEmptyConnection: NormalizedConnection = {
23+
url: "",
24+
graphDbUrl: "",
25+
queryEngine: "gremlin",
26+
proxyConnection: false,
27+
awsAuthEnabled: false,
28+
};
29+
2030
describe("mergedConfiguration", () => {
2131
it("should produce empty defaults when empty object is passed", () => {
2232
const config = {} as RawConfiguration;
2333
const result = mergeConfiguration(null, config, {});
2434

2535
expect(result).toEqual({
26-
connection: {
27-
graphDbUrl: "",
28-
queryEngine: "gremlin",
29-
url: "",
30-
},
36+
connection: defaultEmptyConnection,
3137
schema: {
3238
edges: [],
3339
vertices: [],
@@ -44,8 +50,7 @@ describe("mergedConfiguration", () => {
4450
expect(result).toEqual({
4551
...config,
4652
connection: {
47-
url: "",
48-
graphDbUrl: "",
53+
...defaultEmptyConnection,
4954
...config.connection,
5055
},
5156
schema: {
@@ -84,6 +89,7 @@ describe("mergedConfiguration", () => {
8489
expect(result).toEqual({
8590
...config,
8691
connection: {
92+
...defaultEmptyConnection,
8793
...config.connection,
8894
url: config.connection?.url ?? "",
8995
graphDbUrl: config.connection?.graphDbUrl ?? "",
@@ -135,6 +141,7 @@ describe("mergedConfiguration", () => {
135141
expect(result).toEqual({
136142
...config,
137143
connection: {
144+
...defaultEmptyConnection,
138145
...config.connection,
139146
url: config.connection?.url ?? "",
140147
graphDbUrl: config.connection?.graphDbUrl ?? "",

0 commit comments

Comments
 (0)