Documentation Center

GraphQL Schema Definition Language support directives

To validate and transform content on the server after fetching the content through a GraphQL query, use a number of support directives in the GraphQL Schema Definition Language.

Directives and their arguments

The following directives exist:
Directive nameDescriptionArguments
@sourceRemaps a field to another field by path (a relative path from the current position).path, singleResult
@globalSourceRemaps a field to another field by path (absolute in the JSON fragment).path
@typeSourceCopies all fields from the object in $path into the declared object.path
@rawReturns the JSON of the object as a raw, escaped string.(none)
@semanticReturns the data defined in the schema definitions.(none)
@dataProviderUse this directive to define the JSON data source.dataSource
The arguments mean the following:
path
The JSON relative path for field value search. This argument support the specifications of JsonPath. For more information about JsonPath, refer to https://github.com/json-path/JsonPath.
singleResult
A flag that, if set to true, causes the directive to convert any single-element array into an object (that is, to remove [ ] in the resulting JSON if the array contains only one item).
dataSource
The source of the content JSON. Must be one of the following values:
ValueDescription
pipelinePageJSON Page content from the pipeline
pipelineComponentPresentationJSON Component Presentation content from the pipeline

@source code examples

Content
{
  "Page": {
    "Article": {
      "body": {
        "content": "test content",
        "image": "image"
      },
      "header": "content header"
    }
  }
}
Model
type Page {
  articleBody : String @source(path: "$.Article.body.content")
}
Query
{
  getContent() {
    Page: {
      articleBody
    }
  }
}
Result
{
  "data": {
    "Page": {
      "articleBody": "test content"
    }
  }
}

@globalSource code examples

Content
{
  "Page": {
    "Article": {
      "body": {
        "content": "test content",
        "image": "image"
      },
      "header": "content header"
    }
  }
}
Model
type Page {
  article: Article
}
type Article {
  body: Body
}
type Body {
  content : String
  image : String
  header : String @globalSource(path: "$.Article.header")
}
Query
{
  getContent() {
    Page {
      Article {
        body {
          header
        }
      }
    }
  }
}
Result
{
  "Page": {
   "Article": {
      "body": {
        "header": "content header"
      }
    }
  }
}

@typeSource code examples

Content
{
  "data": {
    "Page": {
      "Article": {
        "body": {
          "content": "test",
          "image": "image",
          "header": "content header"
        }
      }
    }
  }
}
Model
type Page {
  article: Article @typeSource(path: '$.body')
}
type Article {
  header: String
}
Query
{
  getContent() {
    Page: {
      Article: {
        content
        image
        header
      }
    }
  }
}
Result
{
  "data": {
    "Page": {
      "Article": {
        "content": "test",
        "image": "image",
        "header": "content header"
      }
    }
  }
}

@raw code examples

Content
{
  "Page": {
    "content": "test content",
    "header": "content header"
  }
}
Model
type Page {
  rawContent : String @raw
}
Query
getContent() {
  rawContent
}
Result
{
  "data": {
    "rawContent": "{Page\" :{\"content\" : \"test content\", \"header\" : \"content header\"}}"
    }
  }
}

@semantic code examples

Content
{
  "Page": {
    "content": "test content"
  }
}
Model
type Page {
  semanticData : SemanticProperty @semantic(prefix: "P" schema : "http://schema.org")
}
Query
getContent() {
  semanticData {
    prefix
    schema
  }
}
Result
{
  "data": {
    "semanticData": {
      "prefix": "P",
      "schema": "http://schema.org"
    }
  }
}

@dataProvider model code example

type Query {
  getContent() : InternalContent @dataprovider(dataSource: pipelinePage)
}