Skip to content
Console(opens in a new tab)

@skipEmpty

Prunes nodes from a connection when the nested connection at the 'field' dot-path has no edges, recursing upward: a node left with no edges is pruned from its parent too, until a level with a non-empty sibling.

Directives. This directive runs after the query has its answer. It changes what you see, not what the query reads.

Prunes nodes from a connection when the nested connection at the ‘field’ dot-path has no edges, recursing upward: a node left with no edges is pruned from its parent too, until a level with a non-empty sibling. Applied on the connection field itself. Example: legalEntities @skipEmpty(field: “registeredEntities.registrations.roles.edges”) drops registrations whose roles are empty, then registered entities and legal entities left with nothing beneath them.

Argument Type Description
field String! A dot path from each node of this connection to a nested connection, written with field names or aliases. The directive removes each node whose nested connection has no edges, then each parent that the removal leaves empty. A final edges segment is optional.

FIELD.

query {
search(searchInput: {
entityType: BRAND
name: "Safeway"
conditions: { limit: 1 }
}) {
... on Brand {
id
operatingLocations(first: 3) @skipEmpty(field: "phoneNumbers") {
edges { node { id phoneNumbers(first: 1) { edges { node { phoneNumber } } } } }
}
}
}
}

Response, as returned:

{
"data": {
"search": [
{
"id": "0f26fbef-3436-4f85-8bcd-31fe12a4f99a",
"operatingLocations": {
"edges": [
{
"node": {
"id": "0fdb9d12-8533-4116-861c-338262327aa4",
"phoneNumbers": {
"edges": [
{
"node": {
"phoneNumber": "+15413836500"
}
}
]
}
}
},
{
"node": {
"id": "73feac12-0230-4306-87f2-63c266ce7106",
"phoneNumbers": {
"edges": [
{
"node": {
"phoneNumber": "+14104147400"
}
}
]
}
}
},
{
"node": {
"id": "9ae96bd8-9b96-4a0f-be16-e1811d34ec69",
"phoneNumbers": {
"edges": [
…
}