Skip to content
Console(opens in a new tab)

@unique

Removes duplicate values from an array, preserving order.

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

Removes duplicate values from an array, preserving order. Without ‘field’, values are compared directly (scalars by value; objects are never considered duplicates). With ‘field’, a dot-separated path (see ‘map’ for path syntax) is resolved on each element and elements are deduplicated by that value instead, keeping the first occurrence. Example: _fn @unique(refs: [“a”, “b”]) returns only distinct values; _fn @unique(refs: [“items”], field: “jobTitle”) keeps the first item per distinct jobTitle.

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 String A dot path to read from each item. The directive keeps the first item for each distinct value at that path.

FIELD.

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

Response, as returned:

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