- 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": [ "c458c91f-907c-4ec1-bbe1-e9b39baee074", "4f378c48-16b0-4a38-8b1f-c1005a2da1cd" ], "operatingLocations": { "edges": [ { "node": { "id": "c458c91f-907c-4ec1-bbe1-e9b39baee074" } }, { "node": { "id": "4f378c48-16b0-4a38-8b1f-c1005a2da1cd" } }, { "node": { "id": "8d41aec8-aec8-4d3d-b7b4-84e81b53d45a" } }, { "node": { "id": "3d5e00ad-cf09-4711-bc94-3d238a2ae9c5" } }, { "node": { "id": "4f56b5d9-8e65-473e-ae5a-f54a1e2cc048" } } ] } } ] …}