0.1.6 • Published 10 months ago

@graphscope/studio-driver v0.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Studio Driver

@graphscope/studio-driver aims to encapsulate the functionalities of neo4j-driver and gremlin, allowing developers to initiate graph query requests directly from both the server and client sides. This library provides a unified interface for interacting with graph databases, simplifying the process of sending and handling queries in web applications.

Browser

import { queryGraph, CypherDriver, GremlinDriver } from '@graphscope/studio-driver';

const query_initiation = 'Browser'; // Browser or Server

const onClick = async () => {
  const _params = {
    endpoint: 'http://localhost:8182',
    script: 'Match (n) return n',
    language: 'cypher',
  };

  if (query_initiation === 'Browser') {
    return queryGraph(_params);
  }
  if (query_initiation === 'Server') {
    return await fetch('/query', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(_params),
    })
      .then(res => res.json())
      .then(res => {
        if (res.success) {
          return res.data;
        }
        return {
          nodes: [],
          edges: [],
        };
      });
  }
};
const App = () => {
  return <button onClick={onClick}>query data</button>;
};

Node.js

const express = require('express');
const { CypherDriver, GremlinDriver, queryGraph } = require('@graphscope/studio-driver');
const app = express();
app.use(express.json());
app.post('/query', async (req, res) => {
  const { script, language, endpoint } = req.body;
  const data = await queryGraph({ script, language, endpoint }, { debugger: false });
  res.send({
    success: true,
    data: data,
  });
});
app.listen(3000, () => {});
  • endpoint: The URL of your graph database endpoint.
  • script: The query script to run (e.g., Cypher or Gremlin script).
  • language: The query language (either 'cypher' or 'gremlin').
0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

12 months ago