Skip to content

Commit

Permalink
Refactor PG summary ExpressJS route to match Neptune endpoints (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnchin authored Mar 2, 2024
1 parent 4afffee commit f82a663
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
25 changes: 19 additions & 6 deletions packages/graph-explorer-proxy-server/node-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,26 @@ async function fetchData(res, next, url, options, isIamEnabled, region, serviceT
fetchData(res, next, rawUrl, requestOptions, isIamEnabled, region, serviceType);
});

// GET endpoint to retrieve statistics summary.
// GET endpoint to retrieve PropertyGraph statistics summary for Neptune Analytics.
app.get("/summary", async (req, res, next) => {
const isIamEnabled = !!req.headers["aws-neptune-region"];
const serviceType = isIamEnabled ? (req.headers["service-type"] ?? DEFAULT_SERVICE_TYPE) : "";
const rawUrl = `${req.headers["graph-db-connection-url"]}/summary?mode=detailed`;

const requestOptions = {
method: "GET",
};

const region = isIamEnabled ? req.headers["aws-neptune-region"] : "";

fetchData(res, next, rawUrl, requestOptions, isIamEnabled, region, serviceType);
});

// GET endpoint to retrieve PropertyGraph statistics summary for Neptune DB.
app.get("/pg/statistics/summary", async (req, res, next) => {
const isIamEnabled = !!req.headers["aws-neptune-region"];
const serviceType = isIamEnabled ? (req.headers["service-type"] ?? DEFAULT_SERVICE_TYPE) : "";
const rawUrl = serviceType === NEPTUNE_ANALYTICS_SERVICE_TYPE
? `${req.headers["graph-db-connection-url"]}/summary?mode=detailed`
: `${req.headers["graph-db-connection-url"]}/pg/statistics/summary?mode=detailed`;
const rawUrl = `${req.headers["graph-db-connection-url"]}/pg/statistics/summary?mode=detailed`;

const requestOptions = {
method: "GET",
Expand All @@ -264,15 +277,15 @@ async function fetchData(res, next, url, options, isIamEnabled, region, serviceT

// GET endpoint to retrieve RDF statistics summary.
app.get("/rdf/statistics/summary", async (req, res, next) => {
const isIamEnabled = !!req.headers["aws-neptune-region"];
const serviceType = isIamEnabled ? (req.headers["service-type"] ?? DEFAULT_SERVICE_TYPE) : "";
const rawUrl = `${req.headers["graph-db-connection-url"]}/rdf/statistics/summary?mode=detailed`;

const requestOptions = {
method: "GET",
};

const isIamEnabled = !!req.headers["aws-neptune-region"];
const region = isIamEnabled ? req.headers["aws-neptune-region"] : "";
const serviceType = isIamEnabled ? (req.headers["service-type"] ?? DEFAULT_SERVICE_TYPE) : "";

fetchData(res, next, rawUrl, requestOptions, isIamEnabled, region, serviceType);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { GraphSummary } from "./types";
import { useCallback } from "react";
import useGEFetch from "../useGEFetch";
import { ConnectionConfig, useConfiguration } from "../../core";
import { DEFAULT_SERVICE_TYPE } from "../../utils/constants";


const useOpenCypher = () => {
const connection = useConfiguration()?.connection as ConnectionConfig | undefined;
const useFetch = useGEFetch();
const url = connection?.url;
const serviceType = connection?.serviceType || DEFAULT_SERVICE_TYPE;

const _openCypherFetch = useCallback((options) => {
return async (queryTemplate: string) => {
Expand All @@ -28,11 +30,15 @@ const useOpenCypher = () => {
};
}, [url, useFetch]);

const fetchSchemaFunc = useCallback(async (options) => {
const fetchSchemaFunc = useCallback(async (options: any) => {
const ops = { ...options, disableCache: true };

let summary;
try {
const response = await useFetch.request(`${url}/pg/statistics/summary?mode=detailed`, {
const endpoint= serviceType === DEFAULT_SERVICE_TYPE
? `${url}/pg/statistics/summary?mode=detailed`
: `${url}/summary?mode=detailed`
const response = await useFetch.request(endpoint, {
method: "GET",
...ops
});
Expand Down

0 comments on commit f82a663

Please sign in to comment.