Singular root fields also accept the filter
parameter, but the filter is spread directly into arguments rather than as a distinct key. As such, filter parameters are passed to the singular root field directly and return the resulting object directly. If no parameters are passed, a random node of that type, if it exists, is returned. Because this random node is explicitly undefined, there is no guarantee of stability of that node across individual builds and rebuilds. If there is no node available to return, null
is returned.
Here is an example of a singular root field query, which retrieves a single node of type blogArticle
by identifying a field and its desired value:
{
blogArticle(id: { slug: "graphql-is-the-best" }) {
id
}
}
Leave a Reply