WordPress 데이터 쿼리
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을 사용하여 필드 값에 function field를 적용합니다:

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