Skip to content
import GraphQueryStreaming from "@arcgis/core/rest/knowledgeGraph/GraphQueryStreaming.js";
Inheritance:
GraphQueryStreamingGraphQueryAccessor
Since
ArcGIS Maps SDK for JavaScript 4.25

Defines a streaming query operation performed on a knowledge graph service's graph resource. The entities and relationships in the graph are queried by sending an Esri implementation of openCypher query.

Streaming query returns results faster than query and in small chunks that can be processed immediately. Streaming query also allows bind parameters.

See also
Examples
// sample streaming query using bind parameters
// to search for entities with a the `name` property that matches a specific string
// or have their geometry within a bounding box.
// get all parts bought by each supplier.
// query returns both the supplier and the part it buys.
const query = `MATCH (s:Supplier)-[:buys_part]-(p:Part)
WHERE s.name=$name OR esri.graph.ST_Intersects($geom, s.geometry)
RETURN s,p`;
KnowledgeGraphModule.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: query,
bindParameters: {
name: "Supplier 1",
geom: new Polygon({
rings: [
[
[-78, 38],
[-78, 39],
[-76, 39],
[-76, 38],
[-78, 38]
],
],
}),
}
}).then((streamingQueryResult)=>{
// streaming query returns a readableStream which must be read to access the returned graph data
readStream(streamingQueryResult);
})
// a function to read the readable stream returned from the above query
const readStream = async (streamingQueryResult) => {
let time = Date.now();
let reader = streamingQueryResult.resultRowsStream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
console.log(`All records returned, stream closed: ${(Date.now() - time) / 1000} seconds`);
break;
}
console.log(`Streaming chunk returned in: ${(Date.now() - time) / 1000} seconds`, value);
// use the results
// list the parts bought by each supplier
let supplierParts = {};
// each element of the result array will contain one supplier and one part it buys
for (var v in value){
let supplier = value[v][0].properties.Name
let part = value [v][1].properties.Name
if(!(supplier in supplierParts)){
supplierParts[supplier] = [];
}
// collect parts by supplier that buys them
supplierParts[supplier].push(part);
console.log(supplierParts);
// result printed to the console: {Supplier 1:[Part1], Supplier 3:[Part2, Part3]}
}
}
} catch (err) {
if (err.name === "AbortError") {
console.log("Request aborted as expected");
} else {
throw err;
}
}
};
// result stream from above query after it has been read
"Streaming chunk returned in: 0.082 seconds"
[
[{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Supplier 1",
"City": "Washington DC",
"EmployeeCount": 31
},
"typeName": "Supplier",
"id": "{57FDF2F3-34C8-48EF-9A3B-76ED9314C4D2}"
},{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Part_ID": 695401,
"Name": "Part1",
"Minimum_quantity": 360
},
"typeName": "Part",
"id": "{IWN51W4-1AW8-A2W6-1AW5F-1AW8F9F4W51AS}",
}],
[{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Supplier 2",
"City": "Baltimore",
"EmployeeCount": 53
},
"typeName": "Supplier",
"id": "{1A4W8F5W-1WA8-5W6A-A1W8-A1W5F8W3S482A}"
},{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Part_ID": 695401,
"Name": "Part2",
"Minimum_quantity": 2500
},
"typeName": "Part",
"id": "{A1W5F8W4F-A1W8-1894-16A5-A86WF4A8SFWD}",
}],
[{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Name": "Supplier 2",
"City": "Baltimore",
"EmployeeCount": 53
},
"typeName": "Supplier",
"id": "{1A4W8F5W-1WA8-5W6A-A1W8-L5H4G8RT1PK3}"
},{
"declaredClass": "esri.rest.knowledgeGraph.Entity",
"properties": {
"Part_ID": 695401,
"Name": "Part3",
"Minimum_quantity": 5000
},
"typeName": "Part",
"id": "{PTJ51FT-KY4H-1GY5-G1Y8-G1Y5K49G8Y4GHJ}",
}]
]
// aborting the query
// create instance of native browser abort controller
const controller = new AbortController();
// create query
KnowledgeGraphModule
.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: "MATCH (n) RETURN n LIMIT 100",
},
{
signal: controller.signal,
}
)
.then((streamingQueryResult) => {
readStream(streamingQueryResult);
})
// indicate that the stream was aborted
.catch((err) => {
if (err.name === "AbortError") {
console.log("Request aborted as expected");
}
// abort the query after half a second
setTimeout(() => {
console.log("Sending abort signal");
controller.abort();
}, 500);

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

bindGeometryQuantizationParameters

Property
Type
InputQuantizationParameters | null | undefined

Custom quantization parameters for input geometry that compresses geometry for transfer to the server. Overrides the default lossless WGS84 quantization.

Example
// sample implementation of an input quantization parameter
// query entities within a bounding box
const query = "MATCH (n) WHERE esri.graph.ST_Intersects($geom, n.geometry) RETURN n"
KnowledgeGraphModule.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: query,
bindParameters: {
param_filter_geom: new Polygon({
rings: [
[
[-89, -89],
[89, -89],
[89, 89],
[-89, 89],
[-89, -89],
],
],
}),
},
inputQuantizationParameters: {
xyResolution: 0.003,
xFalseOrigin: 25,
yFalseOrigin: 25,
zResolution: 1,
zFalseOrigin: 1,
mResolution: 1,
mFalseOrigin: 1,
},
}
}
);

bindParameters

Property
Type
Record<string, ValidBindParameterType> | null | undefined

Specifies a set of parameters containing data to be included in the query.

Note

Check the service definition for the knowledgeGraphService for valid geometry types. Not all external graph stores will supported all geometry types.

Examples
// bind a polygon to search for entities withing a bounding box.
const query = "MATCH (n) WHERE esri.graph.ST_Intersects($geom, n.geometry) RETURN n";
KnowledgeGraphModule.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: query,
bindParameters: {
geom: new Polygon({
rings: [
[
[-89, -89],
[89, -89],
[89, 89],
[-89, 89],
[-89, -89],
],
],
}),
}
}).then((streamingQueryResult)=>{
// streaming query returns a readableStream which must be read to access the returned graph data
readStream(streamingQueryResult);
})
// bind a list of ids
// get all relationships between suppliers and a select list of parts.
const query = "MATCH (s:Supplier)-[rel]-(p:Part) WHERE p.globalid IN $ids RETURN rel";
KnowledgeGraphModule.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: query,
bindParameters: {
ids:[
"{WIHPTR45-1RO5-9HY1-FK50-P1J5U8D1FER7}",
"{SSOE5G4O-T7T8-4G8Y-2RD1-P8D1A7G4S7EA}",
"{2SE8HE8D-81ES-9HY1-1SE8-OPAWON41869S}",
"{1SE8E6G8-5DT8-S8E1-6S8E-D8R4FJ8S8S1S}",
"{SE86I2BD-8R73-2SE8-6S8E-7R8DR86S4SD6}",
"{N2T8K52R-2SDE-1SEG-S8ES-6SE8HUKY6AIN}",
"{2AWAGP86-SESR-5SE8-4SE8-68RD66846SPL}",
],
}),
}
}).then((streamingQueryResult)=>{
// streaming query returns a readableStream which must be read to access the returned graph data
readStream(streamingQueryResult);
})

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor

The name of the class. The declared class name is formatted as esri.folder.className.

openCypherQuery

inherited Property
Type
string
Inherited from: GraphQuery

The Esri implementation of openCypher query to be executed against the knowledge graph.

Required

executeQuery() will fail if not provided.

Default value
""

outputQuantizationParameters

Property
Type
OutputQuantizationParameters | null | undefined

Used to project the geometry onto a virtual grid, likely representing pixels on the screen. Geometry coordinates are converted to integers by building a grid with a resolution matching the OutputQuantizationParameters.tolerance. Each coordinate is then snapped to one pixel on the grid.

Example
// sample implementation of an output quantization parameter
// query entities within a bounding box.
const query = "MATCH (n) WHERE esri.graph.ST_Intersects($geom, n.geometry) RETURN n"
KnowledgeGraphModule.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: query,
bindParameters: {
geom: new Polygon({
rings: [
[
[-89, -89],
[89, -89],
[89, 89],
[-89, 89],
[-89, -89],
],
],
}),
},
outputQuantizationParameters: {
extent: {
xmax: 30,
xmin: 20,
ymax: 30,
ymin: 20,
},
tolerance: 0.001,
quantizeMode: "view",
}
}
}
);

outputSpatialReference

autocast Property
Type
SpatialReference | null | undefined

Custom output spatial reference parameters for output geometry. Overrides the default lossless WGS84 quantization.

provenanceBehavior

Property
Type
GraphQueryStreamingProvenanceBehavior | null | undefined

Enables provenance to be used and returned in the query. This will only be available if the service has provenance enabled.

Example
// query entities within a bounding box that have a specific provenance.
const query = "MATCH (n), (prov:Provenance)
WHERE esri.graph.ST_Intersects($geom, n.geometry) and prov.instanceID in $idList
RETURN n, prov"
KnowledgeGraphModule.executeQueryStreaming(
knowledgeGraph,
{
openCypherQuery: query,
provenanceBehavior: "include",
bindParameters: {
idList: ['{59ACF2B8-1A28-4825-9228-E0CE1AFF184A}',
'{AFF1A752-1A28-4825-9228-EFFEE152184A}',
'{4825AABB-1A28-4825-9228-E0CE1AFF9712}'],
geom: new Polygon({
rings: [
[
[-89, -89],
[89, -89],
[89, 89],
[-89, 89],
[-89, -89],
],
],
}),
},
outputQuantizationParameters: {
extent: {
xmax: 30,
xmin: 20,
ymax: 30,
ymin: 20,
},
tolerance: 0.001,
quantizeMode: "view",
}
}
);

Type definitions

GraphQueryStreamingProvenanceBehavior

Type definition
Type
"exclude" | "include"