Запрос данных WordPressДирективы
Директивы
Директивы предоставляются расширениями Gato GraphQL. Ниже приведены лишь несколько примеров.
Директивы операций
Создайте конвейер операций с помощью @depends и выполняйте одну из операций условно, основываясь на динамическом значении, с помощью @skip и @include:
query CheckIfPostExists($id: ID!) {
# Initialize the dynamic variable to `false`
postExists: _echo(value: false)
@export(as: "postExists")
post(by: { id: $id }) {
# Found the Post => Set dynamic variable to `true`
postExists: _echo(value: true)
@export(as: "postExists")
}
}
mutation ExecuteOnlyIfPostExists
@depends(on: "CheckIfPostExists")
@include(if: $postExists)
{
# Do something...
}Директивы полей
Преобразуйте поле в нижний регистр с помощью @strLowerCase:
{
posts(pagination: { limit: 3 }) {
id
title @strLowerCase
}
}Укажите значение по умолчанию для поля с помощью @default:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @default(value: 1505) {
id
src
}
}
}Удалите вывод поля из ответа с помощью @remove:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @remove(condition: IS_NULL) {
src
}
sourceFeaturedImage: featuredImage {
src
}
}
}Примените функциональное поле к значению некоторого поля с помощью @passOnwards и @applyFunction:
{
posts {
id
hasComments
notHasComments: hasComments
@passOnwards(as: "postHasComments")
@applyFunction(
name: "_not"
arguments: {
value: $postHasComments
},
setResultInResponse: true
)
}
}