WordPress-Daten abfragenDirektiven
Direktiven
Direktiven werden über Gato GraphQL-Erweiterungen bereitgestellt. Hier sind nur einige Beispiele.
Operationsdirektiven
Erstelle eine Operations-Pipeline über @depends und führe eine ihrer Operationen bedingt aus, basierend auf einem dynamischen Wert, über @skip und @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...
}Felddirektiven
Wandle ein Feld über @strLowerCase in Kleinbuchstaben um:
{
posts(pagination: { limit: 3 }) {
id
title @strLowerCase
}
}Gib einem Feld über @default einen Standardwert:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @default(value: 1505) {
id
src
}
}
}Entferne die Feldausgabe aus der Antwort über @remove:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @remove(condition: IS_NULL) {
src
}
sourceFeaturedImage: featuredImage {
src
}
}
}Wende ein Function Field auf einen Feldwert an, über @passOnwards und @applyFunction:
{
posts {
id
hasComments
notHasComments: hasComments
@passOnwards(as: "postHasComments")
@applyFunction(
name: "_not"
arguments: {
value: $postHasComments
},
setResultInResponse: true
)
}
}