Function getGraphNodesOfType

  • Retrieves graph nodes of a specific type from the given graph.

    Type Parameters

    Parameters

    • graph: TGraph

      The graph to retrieve nodes from.

    • types: TTypes

      The types of nodes to retrieve.

    Returns GetGraphNodesofTypeResult<TGraph, TTypes>

    An array if a string was provided for the types (single result), or an object of arrays if an object or array was provided for the types (multiple results). The node type is inferred from the node's type attribute if it was specified using a literal string.

    Example

    type LanguageAttributes = {
    _type: "language"
    country: string
    }

    type CountryAttributes = {
    _type: "country"
    continent: string
    }

    type StringResult = NodeEntry<CountryAttributes>[]

    type ArrayOrObjectResult = {
    language: NodeEntry<LanguageAttributes>[]
    country: NodeEntry<CountryAttributes>[]
    }

    const graph = new Graph<LanguageAttributes | CountryAttributes>()
    // After adding nodes...


    // StringResult is inferred
    const result = getGraphNodesOfType(graph, "country")

    // ArrayOrObjectResult is inferred
    const result2 = getGraphNodesOfType(graph, ["language", "country"])

    // ArrayOrObjectResult is inferred
    const result3 = getGraphNodesOfType(graph, {
    language: true,
    country: true,
    })

Generated using TypeDoc