GraphQL#

Navigation supports accessing Node objects via GraphQL. Be sure to read about Craft's GraphQL support (opens new window).

Nodes#

Example#

{
    navigationNodes (navHandle: "mainMenu", level: 1) {
        title
        url
        children {
            title
            url
        }
    }
}
{
    "data": {
        "navigationNodes": [
            {
                "title": "About",
                "url": "http://craft.test/about",
                "children": [
                    {
                        "title": "Who We Are",
                        "url": "http://craft.test/about/who-we-are"
                    }
                ]
            }
        ]
    }
}

The nodes query#

This query is used to query for Node objects. You can also use the singular node to fetch a single node.

ArgumentTypeDescription
id[QueryArgument]Narrows the query results based on the elements’ IDs.
uid[String]Narrows the query results based on the elements’ UIDs.
status[String]Narrows the query results based on the elements’ statuses.
archivedBooleanNarrows the query results to only elements that have been archived.
trashedBooleanNarrows the query results to only elements that have been soft-deleted.
site[String]Determines which site(s) the elements should be queried in. Defaults to the current (requested) site.
siteId[QueryArgument]Determines which site(s) the elements should be queried in. Defaults to the current (requested) site.
uniqueBooleanDetermines whether only elements with unique IDs should be returned by the query.
preferSites[QueryArgument]Determines which site should be selected when querying multi-site elements.
enabledForSiteBooleanNarrows the query results based on whether the elements are enabled in the site they’re being queried in, per the site argument.
title[String]Narrows the query results based on the elements’ titles.
slug[String]Narrows the query results based on the elements’ slugs.
uri[String]Narrows the query results based on the elements’ URIs.
searchStringNarrows the query results to only elements that match a search query.
relatedTo[QueryArgument]Narrows the query results to elements that relate to the provided element IDs. This argument is ignored, if relatedToAll is also used.
relatedToAssets[AssetCriteriaInput]Narrows the query results to elements that relate to an asset list defined with this argument.
relatedToEntries[EntryCriteriaInput]Narrows the query results to elements that relate to an entry list defined with this argument.
relatedToUsers[UserCriteriaInput]Narrows the query results to elements that relate to a use list defined with this argument.
relatedToCategories[CategoryCriteriaInput]Narrows the query results to elements that relate to a category list defined with this argument.
relatedToTags[TagCriteriaInput]Narrows the query results to elements that relate to a tag list defined with this argument.
relatedToAll[QueryArgument]Narrows the query results to elements that relate to all of the provided element IDs. Using this argument will cause relatedTo argument to be ignored. This argument is deprecated. relatedTo: ["and", ...ids] should be used instead.
ref[String]Narrows the query results based on a reference string.
fixedOrderBooleanCauses the query results to be returned in the order specified by the id argument.
inReverseBooleanCauses the query results to be returned in reverse order.
dateCreated[String]Narrows the query results based on the elements’ creation dates.
dateUpdated[String]Narrows the query results based on the elements’ last-updated dates.
offsetIntSets the offset for paginated results.
limitIntSets the limit for paginated results.
orderByStringSets the field the returned elements should be ordered by.
siteSettingsId[QueryArgument]Narrows the query results based on the unique identifier for an element-site relation.
withStructureBooleanExplicitly determines whether the query should join in the structure data.
structureIdIntDetermines which structure data should be joined into the query.
levelIntNarrows the query results based on the elements’ level within the structure.
hasDescendantsBooleanNarrows the query results based on whether the elements have any descendants in their structure.
ancestorOfIntNarrows the query results to only elements that are ancestors of another element in its structure, provided by its ID.
ancestorDistIntNarrows the query results to only elements that are up to a certain distance away from the element in its structure specified by ancestorOf.
descendantOfIntNarrows the query results to only elements that are descendants of another element in its structure provided by its ID.
descendantDistIntNarrows the query results to only elements that are up to a certain distance away from the element in its structure specified by descendantOf.
leavesBooleanNarrows the query results based on whether the elements are “leaves” in their structure (element with no descendants).
nextSiblingOfIntNarrows the query results to only the entry that comes immediately after another element in its structure, provided by its ID.
prevSiblingOfIntNarrows the query results to only the entry that comes immediately before another element in its structure, provided by its ID.
positionedAfterIntNarrows the query results to only entries that are positioned after another element in its structure, provided by its ID.
positionedBeforeIntNarrows the query results to only entries that are positioned before another element in its structure, provided by its ID.
nav'[String]Narrows the query results based on the navigation the node belongs to.
navHandleStringNarrows the query results based on the provided navigation handle.
navIdIntNarrows the query results based on the provided navigation ID.
type[String]Narrows the query results based on the node’s type.

The NodeInterface interface#

This is the interface implemented by all nodes.

FieldTypeDescription
idIDThe ID of the entity.
uidStringThe UID of the entity.
_countIntReturn a number of related elements for a field.
titleStringThe element’s title.
slugStringThe element’s slug.
uriStringThe element’s URI.
enabledBooleanWhether the element is enabled or not.
archivedBooleanWhether the element is archived or not.
siteIdIntThe ID of the site the element is associated with.
siteSettingsIdIDThe unique identifier for an element-site relation.
languageStringThe language of the site element is associated with.
searchScoreStringThe element’s search score, if the search parameter was used when querying for the element.
trashedBooleanWhether the element has been soft-deleted or not.
statusStringThe element’s status.
dateCreatedDateTimeThe date the element was created.
dateUpdatedDateTimeThe date the element was last updated.
lftIntThe element’s left position within its structure.
rgtIntThe element’s right position within its structure.
levelIntThe element’s level within its structure
rootIntThe element’s structure’s root ID.
structureIdIntThe element’s structure ID.
children[NodeInterface]The node’s children.
parentNodeInterfaceThe node’s parent.
prevNodeInterfaceReturns the previous element relative to this one, from a given set of criteria.
nextNodeInterfaceReturns the next element relative to this one, from a given set of criteria.
elementIdIntThe ID of the element this node is linked to.
navIdIntThe ID of the navigation this node belongs to.
navHandleStringThe handle of the navigation this node belongs to.
navNameStringThe name of the navigation this node belongs to.
typeStringThe type of node this is.
classesStringAny additional classes for the node.
customAttributesCustomAttributeAny additional custom attributes for the node.
dataStringAny additional data for the node.
newWindowStringWhether this node should open in a new window.
urlStringThe node’s full URL',
urlSuffixStringThe URL for this navigation item.
nodeUriStringThe node’s URI',
elementElementInterfaceThe element the node links to.

The CustomAttribute interface#

This is the interface used for custom attributes.

FieldTypeDescription
attributeStringThe attribute.
valueStringThe value.

Previous ← Extensibility