1.7.12 • Published 1 month ago

@or-sdk/graph v1.7.12

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago

Graphs SDK

The @or-sdk/graphs package provides a client for working with the Graphs system in OneReach.ai. With this client, you can perform operations such as creating graphs, executing queries, managing graph properties, and working with saved queries.

Concepts

Graph

A graph is a data structure that consists of nodes and relationships between those nodes. In the Graphs system, a graph can represent various types of entities and their relationships, allowing you to organize and structure data in a way that represents real-world scenarios.

Node

A node is an individual entity within a graph that represents a single data item. Nodes can have properties that store information about the entity as key-value pairs. They can also have one or more labels, which help to classify nodes into groups or categories.

Relationship

A relationship is a connection between two nodes in a graph. It represents how the entities are related or connected. Relationships can have properties that store information about the connection as key-value pairs. They also have a relationship type, which helps to classify the relationship based on its purpose or meaning.

Query

A query is a statement that is used to interact with the Graphs system, including creating, updating, or retrieving data from a graph. The query language used in the OneReach.ai Graphs system is based on Cypher, which is a powerful and expressive declarative graph query language.

Installation

To install the package, run the following command:

$ npm install @or-sdk/graphs

Usage

To use the Graphs client, you need to create an instance of the class with the appropriate configuration options. You can either provide the direct API URL or the service discovery URL. Here is an example:

import { Graphs } from '@or-sdk/graphs';

// with direct api url
const graphs = new Graphs({
  token: 'my-account-token-string',
  graphUrl: 'http://example.graphs/endpoint'
});

// with service discovery(slower)
const graphs = new Graphs({
  token: 'my-account-token-string',
  discoveryUrl: 'http://example.graphs/endpoint'
});

Once you have an instance of the Graphs client, you can use its methods to interact with the OneReach.ai Graphs system. The available methods are:

query

Execute a query in a graph to retrieve, create, or manipulate data stored in the graph.

Params

  • query: ExecuteQueryArgs - The query object containing the graph name, the query string, and optional query parameters

Example

In this example, the query method executes a Cypher query to match nodes with the label "Place" where the name property equals "CoffeePlace", and returns the matching nodes.

const results = await graphs.query<{ p: Place }>({
  graph: 'places',
  query: 'MATCH (p: Place) WHERE p.name = $name RETURN p',
  params: { name: 'CoffeePlace' },
});

// Example response
[
  {
    p: {
      id: 1,
      labels: ['Place'],
      properties: {
        name: 'CoffeePlace',
        description: 'A cozy place for coffee lovers',
        lat: 40.7128,
        lng: -74.0060,
      },
    },
  },
]

transaction

Execute a set of queries in a transaction in a specified graph. Transactions are used to perform multiple operations atomically, meaning that if any of the operations fail, all operations in the transaction are rolled back, ensuring data consistency.

Params

  • graph: string - The name of the graph to execute the transaction in
  • queries: ExecuteTransactionArgs[] - The set of queries to be run in the transaction

Example

In this example, the transaction method executes two Cypher queries in a transaction to create two new nodes with the label "Place" and names "place1" and "place2" respectively.

const res = await graphs.transaction('places', [
  {
    query: 'CREATE (p: Place { name: "place1" })',
  },
  {
    query: 'CREATE (p: Place { name: $name })',
    params: { name: 'place2' },
  }
]);

In the event that the second query fails for some reason (for example if a "Place" node with the name "place2" already exists), the transaction will be rolled back and the first node with the name "place1" will not be created.

createGraph

Create a new graph with a specified name and optional description and imageUrl.

Params

  • graph: Graph - The graph object containing the name, and optional description and imageUrl

Example

In this example, the createGraph method creates a new graph with the name "places", description "A graph of places and their relationships", and an imageUrl for the graph's icon.

const result = await graphs.createGraph({
  name: 'places',
  description: 'A graph of places and their relationships',
  imageUrl: 'http://example.com/graph-icon.png',
});

// Example response
{
  ok: 1,
}

listGraphs

Retrieve a list of graphs from the Graphs system, optionally filtering by a graph name.

Params

  • name: string (optional) - The name of the graph to search for.

Returns

  • Promise<List<Graph>>: A promise containing a list of graph objects.

Example

In this example, the listGraphs method fetches a list of graphs from the Graphs system.

const graphsList = await graphs.listGraphs();

console.log(graphsList.items);
// Example output
// [
//   {
//     name: 'places',
//     description: 'A graph of places and their relationships',
//     imageUrl: 'http://example.com/graph-icon.png',
//   },
//   {
//     name: 'people',
//     description: 'A graph of people and their relationships',
//     imageUrl: 'http://example.com/people-graph-icon.png',
//   },
// ]

// If you want to search for a specific graph by name
const specificGraphsList = await graphs.listGraphs('places');

console.log(specificGraphsList.items);
// Example output
// [
//   {
//     name: 'places',
//     description: 'A graph of places and their relationships',
//     imageUrl: 'http://example.com/graph-icon.png',
//   },
// ]

The listGraphs method helps you fetch information about the available graphs or a specific graph by name so you can manage them or execute queries on them using other methods available in the SDK.

getGraphInfo

Retrieve detailed information about a graph, including its labels and relationship types, by specifying its name.

Params

  • name: string - The name of the graph for which you want to obtain information.

Returns

  • Promise<GraphInfo>: A promise containing information about the requested graph.

Example

In this example, the getGraphInfo method fetches information about the "places" graph.

const graphInfo = await graphs.getGraphInfo("places");

console.log(graphInfo);
// Example output
// {
//   name: 'places',
//   description: 'A graph of places and their relationships',
//   imageUrl: 'http://example.com/graph-icon.png',
//   labels: ['Place', 'City', 'Country'],
//   relationshipTypes: ['LOCATED_IN', 'CONNECTED_TO']
//   propertyKeys: ['lat', 'lon', 'name', 'zipCode']
// }

The getGraphInfo method allows you to retrieve detailed information about a specific graph, such as its labels and relationship types, so you can understand the structure of the graph and use this information when working with queries or managing the graph.

updateGraph

Update the properties of an existing graph in the Graphs system, such as the description or imageUrl.

Params

  • graph: Graph - The graph object containing the name of the graph to update, and any properties (description or imageUrl) that you want to update.

Returns

  • Promise<WriteResponse>: A promise containing an object with a property 'ok' indicating the success of the update operation.

Example

In this example, the updateGraph method updates the description and imageUrl properties of an existing graph named "places".

const updateResult = await graphs.updateGraph({
  name: 'places',
  description: 'An updated description for the places graph',
  imageUrl: 'http://example.com/updated-graph-icon.png',
});

console.log(updateResult);
// Example output
// { ok: 1 }

The updateGraph method helps you modify the properties of an existing graph in the Graphs system. Keep in mind that you need to provide the name property of the graph you want to update, along with any of the properties you want to modify (description or imageUrl).

deleteGraph

Delete a graph by its name from the Graphs system.

Params

  • name: string - The name of the graph to delete.

Returns

  • Promise<WriteResponse>: A promise containing a write response object indicating the success status of the operation.

Example

In this example, the deleteGraph method deletes a graph with the name "places" from the Graphs system.

const result = await graphs.deleteGraph('places');

console.log(result);
// Example output
// {
//   ok: 1,
// }

Using the deleteGraph method, you can remove a graph from the Graphs system if you no longer need it or if you want to clean up resources. Keep in mind that deleting a graph permanently removes its data and cannot be undone. Ensure you have proper backups or data exports before performing this operation.

saveQuery

Save a query to the Graphs system for future reuse. This allows you to store frequently used queries for easy access and execution.

Params

  • graph: string - The name of the graph that the query belongs to.
  • query: Query - The query object containing the name, query string, and optional description and parameters.

Returns

  • Promise<WriteResponse>: A promise containing a write response object indicating the success of the operation.

Example

In this example, the saveQuery method saves a query to the Graphs system for the "places" graph. The query finds places with the label "Place" that have a name property equal to a given value.

const query: Query = {
  name: 'findPlaceByName',
  query: 'MATCH (p: Place) WHERE p.name = $name RETURN p',
  description: 'Find a place by its name',
  params: { name: 'string' },
};

const result = await graphs.saveQuery('places', query);

// Example response
// {
//   ok: 1,
// }

The saveQuery method makes it easy to store frequently used queries to the Graphs system, allowing you to execute them later without defining the query each time. You can also manage the saved queries using other methods available in the SDK, such as listQueries, getQuery, and deleteQuery.

listQueries

Retrieve a list of saved queries for a specific graph, optionally filtering by a query name.

Params

  • graph: string - The name of the graph for which to list saved queries.
  • name: string (optional) - The name of the query to search for.

Returns

  • Promise<List<Query>>: A promise containing a list of saved query objects.

Example

In this example, the listQueries method fetches a list of saved queries for a graph named "places".

const queriesList = await graphs.listQueries('places');

console.log(queriesList.items);
// Example output
// [
//   {
//     name: 'find_place_by_name',
//     query: 'MATCH (p:Place) WHERE p.name = $name RETURN p',
//     description: 'Find a place by its name',
//     params: { name: 'string' },
//   },
//   {
//     name: 'find_nearby_places',
//     query: 'MATCH (p:Place) WHERE p.lat between $latMin and $latMax AND p.lng between $lngMin and $lngMax RETURN p',
//     description: 'Find nearby places based on latitude and longitude ranges',
//     params: { latMin: 'number', latMax: 'number', lngMin: 'number', lngMax: 'number' },
//   },
// ]

// If you want to search for a specific saved query by name
const specificQueriesList = await graphs.listQueries('places', 'find_place_by_name');

console.log(specificQueriesList.items);
// Example output
// [
//   {
//     name: 'find_place_by_name',
//     query: 'MATCH (p:Place) WHERE p.name = $name RETURN p',
//     description: 'Find a place by its name',
//     params: { name: 'string' },
//   },
// ]

The listQueries method allows you to fetch information about saved queries for a specific graph so you can execute them or manage them using other methods available in the SDK.

getQuery

Retrieve a single saved query by its name from a specified graph.

Params

  • graph: string - The name of the graph to which the saved query belongs.
  • name: string - The name of the saved query to fetch.

Returns

  • Promise<Query>: A promise containing a query object with details of the saved query.

Example

In this example, the getQuery method retrieves a saved query named "find_places" from the "places" graph.

const query = await graphs.getQuery('places', 'find_places');

console.log(query);
// Example output
// {
//   name: 'find_places',
//   query: 'MATCH (p: Place) WHERE p.name = $name RETURN p',
//   description: 'Find places by name',
//   params: { name: 'string' },
// }

The getQuery method helps you fetch the details of a specific saved query from a graph so that you can review its functionality, update its properties, or delete it if necessary using other SDK methods.

deleteQuery

Delete a saved query from a graph in the Graphs system.

Params

  • graph: string - The name of the graph the saved query belongs to.
  • name: string - The name of the saved query to delete.

Returns

  • Promise<WriteResponse>: A promise containing the write response indicating the success or failure of the deletion.

Example

In this example, the deleteQuery method deletes a saved query named "findPopularPlaces" from the "places" graph.

const result = await graphs.deleteQuery('places', 'findPopularPlaces');

console.log(result);
// Example output
// {
//   ok: 1,
// }

Use the deleteQuery method to maintain and manage your saved queries in a graph by deleting the ones that are no longer needed or relevant. This helps with keeping your Graphs system organized and efficient.

1.7.12

1 month ago

1.7.11

1 month ago

1.7.10

1 month ago

1.7.9

2 months ago

1.7.9-beta.2500.0

2 months ago

1.7.8

3 months ago

1.7.8-beta.2464.0

3 months ago

1.7.8-beta.2462.0

3 months ago

1.7.8-beta.2459.0

3 months ago

1.7.7

3 months ago

1.7.7-beta.2432.0

3 months ago

1.7.7-beta.2441.0

3 months ago

1.7.7-beta.2453.0

3 months ago

1.7.7-beta.2438.0

3 months ago

1.7.7-beta.2436.0

3 months ago

1.7.7-beta.2419.0

3 months ago

1.7.6

3 months ago

1.7.6-beta.2401.0

3 months ago

1.7.6-beta.2397.0

3 months ago

1.7.6-beta.2398.0

3 months ago

1.7.6-beta.2396.0

3 months ago

1.7.5

3 months ago

1.7.5-beta.2391.0

3 months ago

1.7.5-beta.2384.0

3 months ago

1.7.4

3 months ago

1.7.2-beta.2374.0

3 months ago

1.7.5-beta.2382.0

3 months ago

1.7.5-beta.2379.0

3 months ago

1.7.4-beta.2371.0

3 months ago

1.7.5-beta.2383.0

3 months ago

1.7.2-beta.2373.0

3 months ago

1.7.3-beta.2369.0

3 months ago

1.7.2-beta.2367.0

3 months ago

1.7.2-beta.2366.0

3 months ago

1.7.3

3 months ago

1.7.2

3 months ago

1.7.2-beta.2364.0

3 months ago

1.7.2-beta.2363.0

3 months ago

1.7.2-beta.2359.0

3 months ago

1.7.2-beta.2365.0

3 months ago

1.7.2-beta.2353.0

3 months ago

1.7.2-beta.2356.0

3 months ago

1.7.2-beta.2355.0

3 months ago

1.7.2-beta.2354.0

3 months ago

1.7.2-beta.2300.0

4 months ago

1.7.2-beta.2259.0

4 months ago

1.7.2-beta.2251.0

4 months ago

1.7.2-beta.2158.0

5 months ago

1.7.1-beta.2147.0

5 months ago

1.7.2-beta.2150.0

5 months ago

1.7.1-beta.2129.0

5 months ago

1.7.1

5 months ago

1.6.1

8 months ago

1.6.0

9 months ago

1.7.1-beta.1953.0

7 months ago

1.6.2-beta.1847.0

8 months ago

1.7.1-beta.2081.0

6 months ago

1.7.1-beta.1867.0

7 months ago

1.6.2-beta.1835.0

8 months ago

1.6.2-beta.1850.0

8 months ago

1.7.1-beta.2078.0

6 months ago

1.5.0

10 months ago

1.6.1-beta.1806.0

8 months ago

1.7.1-beta.2102.0

5 months ago

1.7.1-beta.2125.0

5 months ago

1.7.1-beta.2092.0

5 months ago

1.6.2-beta.1836.0

8 months ago

1.7.1-beta.1943.0

7 months ago

1.6.1-beta.1747.0

9 months ago

1.6.1-beta.1698.0

9 months ago

1.6.1-beta.1810.0

8 months ago

1.7.1-beta.2104.0

5 months ago

1.6.2-beta.1846.0

8 months ago

1.7.1-beta.2082.0

6 months ago

1.6.0-beta.1676.0

9 months ago

1.7.1-beta.2079.0

6 months ago

1.6.1-beta.1811.0

8 months ago

1.6.2-beta.1834.0

8 months ago

1.6.1-beta.1692.0

9 months ago

1.6.1-beta.1809.0

8 months ago

1.7.1-beta.2097.0

5 months ago

1.6.1-beta.1812.0

8 months ago

1.7.1-beta.1946.0

7 months ago

1.6.2-beta.1839.0

8 months ago

1.6.2-beta.1831.0

8 months ago

1.6.1-beta.1693.0

9 months ago

1.6.0-beta.1613.0

10 months ago

1.7.1-beta.1935.0

7 months ago

1.7.1-beta.2084.0

6 months ago

1.6.1-beta.1813.0

8 months ago

1.6.1-beta.1803.0

8 months ago

1.6.2-beta.1849.0

8 months ago

1.5.0-beta.1561.0

10 months ago

1.6.2-beta.1837.0

8 months ago

1.6.0-beta.1668.0

10 months ago

1.6.1-beta.1804.0

8 months ago

1.7.0

8 months ago

1.7.1-beta.1914.0

7 months ago

1.7.1-beta.2098.0

5 months ago

1.7.1-beta.1866.0

8 months ago

1.6.2-beta.1853.0

8 months ago

1.3.2-beta.1377.0

12 months ago

1.3.2-beta.1407.0

12 months ago

1.3.2-beta.1392.0

12 months ago

1.3.2-beta.1426.0

11 months ago

1.4.1-beta.1469.0

11 months ago

1.3.2-beta.1437.0

11 months ago

1.4.1-beta.1465.0

11 months ago

1.3.2-beta.1376.0

12 months ago

1.3.2-beta.1406.0

12 months ago

1.3.2-beta.1395.0

12 months ago

1.4.2-beta.1475.0

11 months ago

1.4.1-beta.1471.0

11 months ago

1.3.2-beta.1436.0

11 months ago

1.3.2-beta.1361.0

12 months ago

1.4.1-beta.1468.0

11 months ago

1.4.1-beta.1464.0

11 months ago

1.3.2-beta.1369.0

12 months ago

1.3.2-beta.1390.0

12 months ago

1.3.2-beta.1424.0

11 months ago

1.4.1

11 months ago

1.4.0

11 months ago

1.3.2-beta.1405.0

12 months ago

1.4.2-beta.1474.0

11 months ago

1.3.2-beta.1379.0

12 months ago

1.4.1-beta.1454.0

11 months ago

1.3.2-beta.1416.0

12 months ago

1.3.2-beta.1368.0

12 months ago

1.3.2

11 months ago

1.3.2-beta.1370.0

12 months ago

1.4.0-beta.1448.0

11 months ago

1.3.2-beta.1378.0

12 months ago

1.3.2-beta.1359.0

12 months ago

1.3.2-beta.1419.0

12 months ago

1.3.2-beta.1367.0

12 months ago

1.1.1

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

0.27.1

1 year ago

0.27.0

1 year ago

1.1.0

1 year ago

0.26.8

1 year ago

0.26.7

1 year ago

0.26.6

1 year ago

0.26.3

2 years ago

0.26.2

2 years ago

0.26.5

2 years ago

0.26.4

2 years ago

0.24.5-411.0

2 years ago

0.25.3

2 years ago

0.25.2

2 years ago

0.25.0

2 years ago

0.24.5-421.0

2 years ago

0.24.5-418.0

2 years ago

0.24.5

2 years ago

0.26.1

2 years ago

0.26.0

2 years ago

0.24.5-410.0

2 years ago

0.24.7

2 years ago

0.24.6

2 years ago

0.24.4-397.0

2 years ago

0.24.4

2 years ago

0.24.3

2 years ago

0.24.2

2 years ago

0.24.2-334.0

2 years ago

0.24.3-385.0

2 years ago

0.24.3-384.0

2 years ago

0.24.3-346.0

2 years ago

0.24.1

2 years ago

0.24.1-276.0

2 years ago

0.24.0

2 years ago

0.23.2-262.0

2 years ago

0.23.1

2 years ago

0.23.1-258.0

2 years ago

0.23.0

2 years ago

0.22.5-251.0

2 years ago