Skip to content

@graphty/graphty-element / index / defineSource

Function: defineSource() ​

defineSource<P>(source): GraphSource<P>

Defined in: graph-io/dist/src/sources/define.d.ts:38

Define a network source: returns it unchanged, with its parameter type inferred, after the registration checks (an id of lowercase letters, digits and dashes; exactly one of records, file and import; declared features backed by methods). A malformed source throws an ImportError whose issue.code is E_SOURCE_INVALID. Experimental.

Type Parameters ​

P ​

P

Parameters ​

source ​

GraphSource<P>

the source

Returns ​

GraphSource<P>

the same source

Example ​

ts
const people = defineSource({
    id: "people",
    async records(params: { team: string }, ctx) {
        const rows = await ctx.fetchJson<{ id: string; name: string }[]>(`/api/people?team=${params.team}`);
        return { nodes: rows };
    },
});