- Docs
- API reference
- Endpoints and schemas
- GraphQL
- Directives
@slice
Returns a subset of an array OR string by start/end index.
Directives. This directive runs after the query has its answer. It changes what you see, not what the query reads.
Returns a subset of an array OR string by start/end index. Supports negative indices. Example: _fn @array(refs: [“a”, “b”, “c”]) @slice(start: 0, end: 2) returns the first two elements.
Arguments
Section titled “Arguments”| Argument | Type | Description |
|---|---|---|
start |
Int |
The index of the first item or character to keep. A negative value counts back from the end. |
end |
Int |
The index to stop before. A negative value counts back from the end. If you omit end or set it to 0, the slice runs to the end. |
Where it goes
Section titled “Where it goes”FIELD.
Example
Section titled “Example”query { search(searchInput: { entityType: BRAND name: "Safeway" conditions: { limit: 1 } }) { ... on Brand { id firstTwo: _fn @map(refs: ["operatingLocations"], field: "edges.*.node.id") @slice(start: 0, end: 2) operatingLocations(first: 5) { edges { node { id } } } } }}Response, as returned:
{ "data": { "search": [ { "id": "0f26fbef-3436-4f85-8bcd-31fe12a4f99a", "firstTwo": [ "0fdb9d12-8533-4116-861c-338262327aa4", "73feac12-0230-4306-87f2-63c266ce7106" ], "operatingLocations": { "edges": [ { "node": { "id": "0fdb9d12-8533-4116-861c-338262327aa4" } }, { "node": { "id": "73feac12-0230-4306-87f2-63c266ce7106" } }, { "node": { "id": "9ae96bd8-9b96-4a0f-be16-e1811d34ec69" } }, { "node": { "id": "1057dea3-0592-437c-977f-638bf32dba70" } }, { "node": { "id": "3e4bc32c-7ae3-4076-9fd5-0d98010032c9" } } ] } } ] …}