import GraphQueryStreamingResult from "@arcgis/core/rest/knowledgeGraph/GraphQueryStreamingResult.js";const GraphQueryStreamingResult = await $arcgis.import("@arcgis/core/rest/knowledgeGraph/GraphQueryStreamingResult.js");- Inheritance
- GraphQueryStreamingResult→
Accessor
- Since
- ArcGIS Maps SDK for JavaScript 4.25
The result of a executeSearchStreaming() or executeQueryStreaming() on a knowledge graph service. Contains a readable stream of objects that match the search or query criteria. The readable stream must be decoded using a getReader() function in order to access the returned graph data.
- Examples
- // sample executeSearchStreaming that would return a GraphQueryStreamingResultKnowledgeGraphModule.executeSearchStreaming(knowledgeGraph,{searchQuery: "solar",typeCategoryFilter: "entity",returnSearchContext: false,start: 1, // index of the first record to returnnum: 200, // return 200 records.namedTypesFilter: ["Company", "Supplier", "Part"],idsFilter: ["{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}","{25WNN24S-41F1-49A4-8412-ANIWN9906E88}","{NS51HE8D-41F1-49A4-8412-5HNIRH9906E8}"]}).then((streamingSearchResult)=>{// the result of a streaming search is a readableStream which requires decoding.readStream(streamingSearchResult)})// the returned readable stream before decoding{resultsRowsStream: {locked: true}}// 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) RETURN s,p`;KnowledgeGraphModule.executeQueryStreaming(knowledgeGraph, query}).then((streamingQueryResult)=>{// streaming query returns a readableStream which must be read to access the returned graph datareadStream(streamingQueryResult);})// a function to read the readable stream returned from the above queryconst 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(`Completed database requests: ${(Date.now() - time) / 1000} seconds`, value);break;}console.log(`Chunk returned in: ${(Date.now() - time) / 1000} seconds`, value);// use the results// list the parts bought by each supplierlet supplierParts = {};// each element of the result array will contain one supplier and one part it buysfor (var v in value){let supplier = value[v][0].properties.Namelet part = value [v][1].properties.Nameif(!(supplier in supplierParts)){supplierParts[supplier] = [];}// collect parts by supplier that buys themsupplierParts[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;}}};// sample result of streaming search result chunk read and printed to the console.// the reader will continue to return chunks until the stream is complete// and all matching results are returned"Streaming chunk returned in: 0.082 seconds"[[{"declaredClass": "esri.rest.knowledgeGraph.Entity","properties": {"Name": "Suncommon","Employee_Count": 400,"energyType": "solar"},"typeName": "Company","id": "{25WNN24S-41F1-49A4-8412-ANIWN9906E88}"}],[{"declaredClass": "esri.rest.knowledgeGraph.Entity","properties": {"Name": "Quality Solar Supply","Supplier_code": "158B","City": "New Orleans",},"typeName": "Supplier","id": "{GE5G1E8D-41F1-49A4-8412-QNG5EG48SG8S}"}],[{"declaredClass": "esri.rest.knowledgeGraph.Entity","properties": {"Name": "Solar panel","panel_type": "Polycrystalline","price_per_unit": 400},"typeName": "Part","id": "{9D2D6AFD-41F1-49A4-8412-CACCC9906E88}",}]]
Constructors
Constructor
Constructor
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| 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.
| Property | Type | Class |
|---|---|---|
| readonly inherited | ||
| |
resultRowsStream
Property
- Type
- ReadableStream
Readable stream of objects matching executeSearchStreaming() or executeQueryStreaming() criteria. Requires decoding using the getReader() method.
- Example
- // example of result decoding.// execute streaming query on a knowledge graphkgModule.executeQueryStreaming(kg,{openCypherQuery: "MATCH (n) RETURN n LIMIT 500",}).then((streamingQueryResult) => {readStream(streamingQueryResult);})//read the ReadableStream resultconst readStream = async (streamingQueryResult) => {let time = Date.now();// create new stream readerlet reader = streamingQueryResult.resultRowsStream.getReader();try {// while the stream is returning datawhile (true) {const { done, value } = await reader.read();// the stream has finished retrieving all matching records from the databaseif (done) {console.log("Client Query stream completed");break;}// do something with the result records returned in each chunkconsole.log(`Client Query Result at Time ${Date.now() - time}:`,value);}// if stream is aborted by user return message, otherwise throw error} catch (err) {if (err.name === "AbortError") {console.log("Request aborted as expected");} else {throw err;}}};