Skip to content
Console(opens in a new tab)

@flatten

Combines several referenced arrays into one flat list.

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

Combines several referenced arrays into one flat list. Each referenced value that is a list contributes its elements; a non-list value contributes itself as a single item. Example: _fn @flatten(refs: [“a”, “b”]) with a=[1,2] and b=3 returns [1, 2, 3].

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
cities: _fn @map(refs: ["operatingLocations"], field: "edges.*.node.addresses.edges.*.node.city") @flatten
operatingLocations(first: 3) { edges { node { addresses(first: 1) { edges { node { city } } } } } }
}
}
}

Response, as returned:

{
"data": {
"search": [
{
"id": "0f26fbef-3436-4f85-8bcd-31fe12a4f99a",
"cities": [
"BEND",
"PRINCE FREDERICK",
"DELTA"
],
"operatingLocations": {
"edges": [
{
"node": {
"addresses": {
"edges": [
{
"node": {
"city": "BEND"
}
}
]
}
}
},
{
"node": {
"addresses": {
"edges": [
{
"node": {
"city": "PRINCE FREDERICK"
}
}
]
}
}
},
{
"node": {
…
}