Array methods
Array methods allow us to modify existing property arrays in Update mutations within these entities:
-
Node
-
Nested Nodes
-
Relationship properties
-
Interfaces
The following operators are available:
-
_POP
-
_PUSH
The POP operator expects a single Int value as input
The PUSH operator conforms to the type of input defined in the type definition.
Examples
Array pop
Suppose we have the following type definition, a Movie with a property array called tags:
type Movie {
title: String
tags: [String]
}
We can pop from this tags
property array.
Before: ['a', 'b', 'c']
After: ['a', 'b']
mutation {
updateMovies (update: { tags_POP: 1 }) {
movies {
title
tags
}
}
}
Or, for more than one property from the array:
Before: ['a', 'b', 'c']
After: ['a']
mutation {
updateMovies (update: { tags_POP: 2 }) {
movies {
title
tags
}
}
}
Similarly, you can have multiple array property fields and update them in the same query:
type Movie {
title: String
tags: [String]
moreTags: [String]
}
We can pop from both the tags
and moreTags
property arrays.
Before:
tags: ['a', 'b', 'c']
moreTags: ['x', 'y', 'z']
After:
tags: ['a', 'b']
moreTags: ['x']
mutation {
updateMovies (update: { tags_POP: 1, moreTags_POP: 2 }) {
movies {
title
tags
moreTags
}
}
}
Array push
Suppose we have the following type definition, a Movie with a property array called tags:
type Movie {
title: String
tags: [String]
}
We can push to this tags
property array.
Before: ['some tag']
After: ['some tag', 'another tag']
mutation {
updateMovies (update: { tags_PUSH: "another tag" }) {
movies {
title
tags
}
}
}
Or push multiple elements in a single update:
Before: ['some tag']
After: ['some tag', 'another tag', 'one more tag']
mutation {
updateMovies (update: { tags_PUSH: ["another tag", "one more tag"] }) {
movies {
title
tags
}
}
}
Similarly, you can have multiple array property fields and update them in the same query:
type Movie {
title: String
tags: [String]
moreTags: [String]
}
We can push to both the tags
and moreTags
property arrays.
Before:
tags: ['some tag']
moreTags: []
After:
tags: ['some tag', 'another tag']
moreTags ['a different tag']
mutation {
updateMovies (update: { tags_PUSH: "another tag", moreTags_PUSH: "a different tag" }) {
movies {
title
tags
moreTags
}
}
}
Array push and pop in one update
It is possible to perform both a push and pop operation in one Update mutation.
Suppose we have the following type definition, a Movie with a property array called tags:
type Movie {
title: String
tags: [String]
moreTags: [String]
}
We can then update both property arrays with either _POP or _PUSH operators.
Before:
tags: ['some tag']
moreTags: []
After:
tags: []
moreTags ['a different tag']
mutation {
updateMovies (update: { tags_POP: 1, moreTags_PUSH: "a different tag" }) {
movies {
title
tags
moreTags
}
}
}
Was this page helpful?