Skip to main content

Context Node

Context Node Screenshot

Overview

The "Context" in Rivet is a set of shared inputs that are accessible in any graph, no matter if they are the entry-point graph, or a subgraph called by another graph. The Context node is used to access these inputs.

The Context Node allows you to access these values in your graph. It is useful for "global values" that every graph can access, without having to pipe the values in as graph inputs. Use the Context Node and contextValues to pass in "global context" to your projects, such as the current date.

Context can currently only be set when Rivet is embedded in a host application. It is passed in using the contextValues parameter to runGraphInFile or createProcessor:

import * as Rivet from '@ironclad/rivet-node';

const contextValues = {
stringContext: 'str',
numberContext: 1,
booleanContext: true,
};

const processor = Rivet.createProcessor({
...etc,
contextValues,
});

The context node has no inputs besides optional ones from the Editor Settings page.

Example 1: Access a string context value

In your parent application, pass a string value into contextValues:

import * as Rivet from '@ironclad/rivet-node';

const contextValues = {
stringContext: 'str',
};

const processor = Rivet.createProcessor({
...etc,
contextValues,
});

In your graph, add a Context node. Set the ID to stringContext, and the Data Type to String. Leave the Default Value empty.

Run your graph while the Remote Debugger is attached. The output of the Context node should be str.

Error Handling

The context node cannot error in normal circumstances. If the context is not set via contextValues, then the default value will be used.

FAQ

Q: Can I use the Context node to pass in the current date and time?

A: Yes, you can pass in the current date as a context value:

const processor = Rivet.createProcessor({
...etc,
contextValues: {
currentDate: new Date(),
},
});

Then, in your graph, add a Context node. Set the ID to currentDate, and the Data Type to Date. Leave the Default Value empty.

Q: Can I use the Context node to pass in a function?

A: No, you cannot pass in a function as a context value. You can only pass in Data Values

Q: Can I use the Context node to pass in a custom data type?

A: No, you cannot pass in a custom data type as a context value. You can only pass in Data Values

See Also