Skip to content

Loading from a service ​

Experimental

Network sources are experimental: names and shapes on this page may still change.

loadFromSource(source, params, options) loads a graph from a network service instead of a file: a repository of networks, a graph database, a REST API. It returns the same { snapshot, format, report } as the other load functions, with format set to "source:<id>" (or the file format a source downloaded) and report.source saying what the load did:

report.sourceWhat it holds
id, versionthe source and its version
endpointthe service's address, origin and path only
requestsrequests sent
bytesresponse bytes read
nextwhere to continue a capped load (pass it as cursor), else null

The built-in sources are ndex (NDEx, the repository of biological networks), cypher with its neo4j and neptune presets, and rest with its openalex preset: see NDEx, Cypher and REST. All of them are experimental. listSources() lists them with their descriptors and samples. To read from your own service, see Writing a source.

Options ​

OptionWhat it does
endpointthe service's address; required unless the source has a default
credentialfrom credentials.bearer, basic, apiKey, awsSigV4 or custom; sent only to the endpoint
limitsmaxNodes, maxEdges, maxBytes, maxRequests, timeoutMs and onLimit ("stop" or "error")
cursorthe report.source.next of a capped load, to continue it
retry{ retries, baseDelayMs, maxDelayMs } (3, 500, 30000), or false
idPrefixprepended to every node id, to keep the ids of two loads apart
allowInsecuresend a credential over plain http: to a host other than this machine
signalcancels the load; it rejects with the signal's reason
onProgress(done, total?, unit): bytes for a downloaded file, items otherwise
fetcha fetch to use instead of the global one, such as replayFetch(recordings) in tests
userAgentsent as User-Agent in Node (browsers do not allow setting it)

Every cap is off unless you set it. Under onLimit: "stop" (the default) a load keeps what came first, warns W_SOURCE_LIMIT and gives report.source.next; under "error" it fails with E_SOURCE_LIMIT.

Requests that are safe to repeat are retried on 429, 502, 503, 504 and network failures, with a random backoff that honors a readable Retry-After. A load that succeeded after retries warns W_SOURCE_RETRIED.

In a browser ​

A browser hides why it refused a request: a CORS refusal, a page on https: asking for http:, a refused connection and a hidden 429 all look the same. graph-io checks what it can before sending and, after a refusal, sends one bodyless request to the origin's root to tell them apart. The error is E_SOURCE_BLOCKED with params.cause: "cors" (the service does not allow this page), "unreachable", "local-network" (a public page asking for a local address, which Chrome asks the reader about) or "unknown". An https: page cannot reach an http: service at all (E_SOURCE_RUNTIME, reason: "insecure-endpoint"); the service needs TLS.

Writing a source lists every error code.