WordPress verilerini sorgula
WordPress verilerini sorgulaDirektifler

Direktifler

Direktifler, Gato GraphQL eklentileri aracılığıyla sağlanır. İşte yalnızca birkaç örnek.

İşlem direktifleri

@depends aracılığıyla bir işlem hattı oluşturun ve @skip ile @include kullanarak dinamik bir değere göre işlemlerden birini koşullu olarak çalıştırın:

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...
}

Alan direktifleri

@strLowerCase aracılığıyla bir alanı küçük harfe dönüştürün:

{
  posts(pagination: { limit: 3 }) {
    id
    title @strLowerCase
  }
}

@default aracılığıyla alan için varsayılan bir değer sağlayın:

query GetFeaturedImages {
  posts(pagination: { limit: 10 }) {
    id
    title
    hasFeaturedImage
    featuredImage @default(value: 1505) {
      id
      src
    }
  }
}

@remove aracılığıyla alan çıktısını yanıttan kaldırın:

query GetFeaturedImages {
  posts(pagination: { limit: 10 }) {
    id
    title
    hasFeaturedImage
    featuredImage @remove(condition: IS_NULL) {
      src
    }
    sourceFeaturedImage: featuredImage {
      src
    }
  }
}

@passOnwards ve @applyFunction aracılığıyla bir alan değerine fonksiyon alanı uygulayın:

{
  posts {
    id
    hasComments
    notHasComments: hasComments
      @passOnwards(as: "postHasComments")
      @applyFunction(
        name: "_not"
        arguments: {
          value: $postHasComments
        },
        setResultInResponse: true
      )
  }
}