Skip to content
Console(opens in a new tab)

@compact

Removes null values from an array.

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

Removes null values from an array. Example: _fn @compact(refs: [“a”, “b”, “c”]) returns only the non-null values.

Argument Type Description
ref String A dot path to one value in the response, relative to the object that holds _fn. Each segment is a field name or alias, a list index, or * for every item of a list. Write ref or refs as the first argument of the directive.
refs [String!] A list of dot paths, written as for ref. The directive takes the list of their values as its input. In a chain of directives, only the first directive reads ref or refs, and each later directive takes the output of the one before it.

FIELD.

query {
search(searchInput: {
entityType: BRAND
name: "Safeway"
conditions: { limit: 1 }
}) {
... on Brand {
id
states: _fn @compact(refs: ["operatingLocations.edges.*.node.addresses.edges.0.node.state"])
operatingLocations(first: 3) { edges { node { addresses(first: 1) { edges { node { state } } } } } }
}
}
}

Response, as returned:

{
"data": {
"search": [
{
"id": "0f26fbef-3436-4f85-8bcd-31fe12a4f99a",
"states": [
[
"OR",
"MD",
"CO"
]
],
"operatingLocations": {
"edges": [
{
"node": {
"addresses": {
"edges": [
{
"node": {
"state": "OR"
}
}
]
}
}
},
{
"node": {
"addresses": {
"edges": [
{
"node": {
"state": "MD"
}
}
]
}
}
},
…
}