Zapytania o dane WordPressDyrektywy
Dyrektywy
Dyrektywy są dostarczane przez rozszerzenia Gato GraphQL. Oto tylko kilka przykładów.
Dyrektywy operacji
Utwórz pipeline operacji za pomocą @depends i wykonaj jedną z operacji warunkowo, na podstawie dynamicznej wartości, za pomocą @skip i @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...
}Dyrektywy pola
Przekształć pole na małe litery za pomocą @strLowerCase:
{
posts(pagination: { limit: 3 }) {
id
title @strLowerCase
}
}Podaj wartość domyślną dla pola za pomocą @default:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @default(value: 1505) {
id
src
}
}
}Usuń dane wyjściowe pola z odpowiedzi za pomocą @remove:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @remove(condition: IS_NULL) {
src
}
sourceFeaturedImage: featuredImage {
src
}
}
}Zastosuj function field na wartości pola za pomocą @passOnwards i @applyFunction:
{
posts {
id
hasComments
notHasComments: hasComments
@passOnwards(as: "postHasComments")
@applyFunction(
name: "_not"
arguments: {
value: $postHasComments
},
setResultInResponse: true
)
}
}