Meta Values
📣 Note: Read more in guide Working with Meta Values.
These are examples of queries to fetch meta data, and filter results by meta.
Querying meta permalink
Fetch single meta value _thumbnail_id
from posts:
{
posts {
id
title
metaValue(key: "_thumbnail_id")
}
}
Fetch array meta value upvotes
from comments:
{
comments {
id
content
upvotes: metaValues(key: "upvotes")
}
}
Filtering by meta permalink
Filter posts where meta key _thumbnail_id
exists:
{
posts(filter: {
metaQuery: {
key: "_thumbnail_id",
compareBy:{
key: {
operator: EXISTS
}
}
}
}) {
id
title
metaValue(key: "_thumbnail_id")
}
}
Filter users where meta entry nickname
has a certain value:
{
users(filter: {
metaQuery: {
key: "nickname",
compareBy:{
stringValue: {
value: "leo"
operator: EQUALS
}
}
}
}) {
id
name
metaValue(key: "nickname")
}
}
Filter comments where meta entry upvotes
(which is an array of integers) has either values 4
or 5
:
{
comments(filter: {
metaQuery: [
{
relation: OR
key: "upvotes",
compareBy: {
arrayValue: {
value: 4
operator: IN
}
}
},
{
key: "upvotes",
compareBy: {
arrayValue: {
value: 5
operator: IN
}
}
}
]}) {
id
content
upvotes: metaValues(key: "upvotes")
}
}