Node Model
Gatsby exposes its internal data store and query capabilities to GraphQL field resolvers on context.nodeModel.
Example Usage
Methods
Get all nodes in the store, or all nodes of a specified type (optionally with limit/skip). Returns slice of result as iterable and total count of nodes.
Parameters
argsqueryObjectQuery arguments (e.g.
limitandskip)typestring | GraphQLOutputTypeType
pageDependenciesObjectOptional page dependency information.
pathstringThe path of the page that depends on the retrieved nodes’ data
connectionTypestringMark this dependency as a connection
Return value
Promise<Object>
Object containing { entries: GatsbyIterable, totalCount: () => Promise<number> }
Get one node in the store. Only returns the first result.
Parameters
argsqueryObjectQuery arguments (e.g.
filter). Doesn’t supportsort,limit,skip.typestring | GraphQLOutputTypeType
pageDependenciesObjectOptional page dependency information.
pathstringThe path of the page that depends on the retrieved nodes’ data
connectionTypestringMark this dependency as a connection
Return value
Promise<Node>
Finds top most ancestor of node that contains passed Object or Array
Parameters
objObject | ArrayObject/Array belonging to Node object or Node object
predicatenodePredicateOptional callback to check if ancestor meets defined conditions
Return value
Node
Top most ancestor if predicate is not specified or first node that meet predicate conditions if predicate is specified
Get a node from the store by ID and optional type.
Parameters
argsObjectidstringID of the requested node
typestring | GraphQLOutputTypeOptional type of the node
pageDependenciesObjectOptional page dependency information.
pathstringThe path of the page that depends on the retrieved nodes’ data
connectionTypestringMark this dependency as a connection
Return value
Node | null
Get nodes from the store by IDs and optional type.
Parameters
argsObjectidsstring[]IDs of the requested nodes
typestring | GraphQLOutputTypeOptional type of the nodes
pageDependenciesObjectOptional page dependency information.
pathstringThe path of the page that depends on the retrieved nodes’ data
connectionTypestringMark this dependency as a connection
Return value
Node[]
Replace the cache either with the value passed on (mainly for tests) or an empty new Map.
Parameters
mapundefined | null | FiltersCache(This cached is used in redux/nodes.js and caches a set of buckets (Sets) of Nodes based on filter and tracks this for each set of types which are actually queried. If the filter targets
iddirectly, only one Node is cached instead of a Set of Nodes. If null, don’t create or use a cache.
Adds link between inline objects/arrays contained in Node object and that Node object.
Parameters
nodeNodeRoot Node
Given a result, that’s either a single node or an array of them, track them using pageDependencies. Defaults to tracking according to current resolver path. Returns the result back.
Parameters
resultNode | Node[]pageDependenciesObjectOptional page dependency information.
pathstringThe path of the page that depends on the retrieved nodes’ data
connectionTypestringMark this dependency as a connection