Gatsby exposes its internal data store and query capabilities to GraphQL field resolvers on context.nodeModel
.
Start building today on
Netlify!
MethodsGet 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.
You can directly return its entries
result in your resolver.
args
query
Object
Query arguments (e.g. limit
and skip
)
type
string | GraphQLOutputType
Type
pageDependencies
Object
Optional page dependency information.
path
string
The path of the page that depends on the retrieved nodes’ data
connectionType
string
Mark this dependency as a connection
Promise<Object>
Object containing { entries: GatsbyIterable, totalCount: () => Promise<number> }
const { entries, totalCount } = await findAll({ type: `MyType` })
const { entries, totalCount } = await findAll({
type: `MyType`,
query: {
sort: { date: `desc` },
filter: { published: { eq: false } },
},
})
const { entries, totalCount } = await findAll({ type: `MyType` })
const count = await totalCount()
const filteredEntries = entries.filter(entry => entry.published)
const filteredEntries = entries.filter(entry => entry.published)
return Array.from(posts).length
Get one node in the store. Only returns the first result. When possible, always use this method instead of fetching all nodes and then filtering them. findOne
is more performant in that regard.
args
query
Object
Query arguments (e.g. filter
). Doesn’t support sort
, limit
, skip
.
type
string | GraphQLOutputType
Type
pageDependencies
Object
Optional page dependency information.
path
string
The path of the page that depends on the retrieved nodes’ data
connectionType
string
Mark this dependency as a connection
const node = await findOne({
type: `MyType`,
query: { filter: { title: { eq: `My Title` } } },
})
Finds top most ancestor of node that contains passed Object or Array
Parametersobj
Object | Array
Object/Array belonging to Node object or Node object
predicate
nodePredicate
Optional callback to check if ancestor meets defined conditions
Node
Top most ancestor if predicate is not specified or first node that meet predicate conditions if predicate is specified
Utility to get a field value from a node, even when that value needs to be materialized first (e.g. nested field that was connected via @link directive)
Parameters
const blogPostNode = {
author: 'author-id-1',
}
getFieldValue(blogPostNode, 'author.name')
Get a node from the store by ID and optional type.
Parametersargs
Object
id
string
ID of the requested node
type
string | GraphQLOutputType
Optional type of the node
pageDependencies
Object
Optional page dependency information.
path
string
The path of the page that depends on the retrieved nodes’ data
connectionType
string
Mark this dependency as a connection
getNodeById({ id: `123` })
getNodeById({ id: `123`, type: `MyType` })
getNodeById({ id: `123` }, { path: `/` })
Get nodes from the store by IDs and optional type.
Parametersargs
Object
ids
string[]
IDs of the requested nodes
type
string | GraphQLOutputType
Optional type of the nodes
pageDependencies
Object
Optional page dependency information.
path
string
The path of the page that depends on the retrieved nodes’ data
connectionType
string
Mark this dependency as a connection
getNodesByIds({ ids: [`123`, `456`] })
getNodesByIds({ ids: [`123`, `456`], type: `MyType` })
getNodesByIds({ ids: [`123`, `456`] }, { path: `/` })
Get the names of all node types in the store.
Replace the cache either with the value passed on (mainly for tests) or an empty new Map.
Parametersmap
undefined | null | FiltersCache
This cache 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 id
directly, 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.
ParametersGiven 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.
ParameterspageDependencies
Object
Optional page dependency information.
path
string
The path of the page that depends on the retrieved nodes’ data
connectionType
string
Mark this dependency as a connection
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4