Consultar datos de WordPressDirectivas
Directivas
Las directivas se proporcionan mediante extensiones de Gato GraphQL. Aquí solo se muestran algunos ejemplos.
Directivas de operación
Crea una operation pipeline mediante @depends, y ejecuta una de sus operaciones de forma condicional, basándose en algún valor dinámico, mediante @skip e @include:
query CheckIfPostExists($id: ID!) {
# Inicializar la variable dinámica a `false`
postExists: _echo(value: false)
@export(as: "postExists")
post(by: { id: $id }) {
# Se encontró la Post => Establecer la variable dinámica a `true`
postExists: _echo(value: true)
@export(as: "postExists")
}
}
mutation ExecuteOnlyIfPostExists
@depends(on: "CheckIfPostExists")
@include(if: $postExists)
{
# Hacer algo...
}Directivas de campo
Transforma un campo a minúsculas mediante @strLowerCase:
{
posts(pagination: { limit: 3 }) {
id
title @strLowerCase
}
}Proporciona un valor por defecto para el campo mediante @default:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @default(value: 1505) {
id
src
}
}
}Elimina la salida del campo de la respuesta mediante @remove:
query GetFeaturedImages {
posts(pagination: { limit: 10 }) {
id
title
hasFeaturedImage
featuredImage @remove(condition: IS_NULL) {
src
}
sourceFeaturedImage: featuredImage {
src
}
}
}Aplica un function field sobre algún valor de campo, mediante @passOnwards y @applyFunction:
{
posts {
id
hasComments
notHasComments: hasComments
@passOnwards(as: "postHasComments")
@applyFunction(
name: "_not"
arguments: {
value: $postHasComments
},
setResultInResponse: true
)
}
}