Examples

Here you can find some examples how you can work with the API.

Queries

All documents related queries return an object that implements the DocumentInterface interface. There are common fields (ie id, displayName, slug, etc) and the custom fields that you defined for the content type. To be able to query these fields you have to create a GraphQL fragment for the content type.

Query a single document

document query in API documentation

By document id

query DocumentQuery(
  $id: ID
) {
  document(
    id: $id
  ) {
    id
    displayName
    slug
    ...HomepageDetails
  }
}

fragment HomepageDetails on HomepageDocument {
  headerImage {
    url
    caption
  }
  websiteTitle
  tagline
  body {
    html
  }
}

By content type and slug

query DocumentQuery(
  $contentTypeApiId: DocumentContentTypeEnum
  $slug: String
) {
  document(
    contentType: $contentTypeApiId
    slug: $slug
  ) {
    id
    displayName
    slug
    ...HomepageDetails
  }
}

fragment HomepageDetails on HomepageDocument {
  headerImage {
    url
    caption
  }
  websiteTitle
  tagline
  body {
    html
  }
}

Query multiple documents

documents query in API documentation

You can query documents by content type and/or predicates. Querying multiple documents work as a standard search function as well. This gives you great flexibility, but comes with a few contraints in defining predicates.

Filtering with content types

query DocumentsQuery(
  $types: [DocumentContentTypeEnum]
) {
  documents(
    types: $types
  ) {
    pagination {
      page
      pageSize
      pageCount
      rowCount
    }
    items {
      id
      displayName
      slug
      ...HomepageDetails
    }
  }
}

fragment HomepageDetails on HomepageDocument {
  headerImage {
    url
    caption
  }
  websiteTitle
  tagline
  body {
    html
  }
}

Filtering with predicates

Predicates are basically SQL conditions that you can define on a document query to filter your result set. For more info see PredicateInput definition.

query GetDocumentsByType(
  $types: [DocumentContentTypeEnum]
  $moviePredicate: PredicateInput
) {
  documents(
    types: $types
    predicates: $moviePredicate
  ) {
    items {
      id
      displayName
      slug
      ...MovieFragment
    }
  }
}

fragment MovieFragment on MovieDocument {
  title
  storyline
  actors {
    items {
      lastName
      firstName
    }
  }
}

Advanced filtering

You can filter not only by the fields of the main document but by fields of referenced documents as well, and of course you can filter a reference list too.

Filtering referenced document list
query GetDocumentsByType(
  $types: [DocumentContentTypeEnum]
  $actorPredicate: PredicateInput
) {
  documents(
    types: $types
  ) {
    items {
      id
      displayName
      slug
      ...MovieFragment
    }
  }
}

fragment MovieFragment on MovieDocument {
  title
  storyline
  actors(predicate: $actorPredicate) {
    items {
      lastName
      firstName
    }
  }
}

Mutations

Create a document

createDocument mutation in API documentation

mutation CreateDocument(
  $document: DocumentInput!
) {
  createDocument(
    document: $document
  ) {
    document {
      id
      displayName
      slug
      lockId
    }
    errors {
      key
      message
    }
  }
}

Update an existing document

updateDocument mutation in API documentation

mutation UpdateDocument(
  $document: DocumentUpdateInput!
) {
  updateDocument(
    document: $document
  ) {
    document {
      id
      displayName
      slug
      lockId
    }
    errors {
      key
      message
    }
  }
}

Publish a document

publishDocument mutation in API documentation

mutation PublishDocument(
  $documentId: ID!
) {
  publishDocument(
    documentId: $documentId
  ) {
    document {
      id
      displayName
      slug
      lockId
      status
    }
    errors {
      key
      message
    }
  }
}

Schedule a document

scheduleDocument mutation in API documentation

mutation ScheduleDocument(
  $documentId: ID!
  $scheduleTime: DateTime!
) {
  scheduleDocument(
    documentId: $documentId
    scheduleTime: $scheduleTime
  ) {
    document {
      id
      displayName
      slug
      lockId
      status
      currentVersion {
        scheduledAt
      }
    }
    errors {
      key
      message
    }
  }
}

Revert a document to the previous version

revertDocumentToPreviousVersionDocument query in API documentation

mutation RevertDocument(
  $documentId: ID!
) {
  revertDocumentToPreviousVersion(
    documentId: $documentId
  ) {
    document {
      id
      displayName
      slug
      lockId
      status
    }
    errors {
      key
      message
    }
  }
}

Unpublish a document

unpublisDocument mutation in API documentation

mutation UnpublishDocument(
  $documentId: ID!
) {
  unpublishDocument(
    documentId: $documentId
  ) {
    document {
      id
      displayName
      slug
      lockId
      status
    }
    errors {
      key
      message
    }
  }
}

Archive a document

archiveDocument mutation in API documentation

mutation ArchiveDocument(
  $documentId: ID!
) {
  archiveDocument(
    documentId: $documentId
  ) {
    document {
      id
      displayName
      slug
      lockId
      status
    }
    errors {
      key
      message
    }
  }
}

Unarchive a document

unarchiveDocument mutation in API documentation

mutation UnarchiveDocument(
  $documentId: ID!
) {
  unarchiveDocument(
    documentId: $documentId
  ) {
    document {
      id
      displayName
      slug
      lockId
      status
    }
    errors {
      key
      message
    }
  }
}

Create a content type

createContentType mutation in API documentation

mutation CreateContentType(
  $contentType: ContentTypeInput!
) {
  createContentType(
    contentType: $contentType
  ) {
    contentType {
      id
      name
      apiId
      description
    }
    errors {
      key
      message
    }
  }
}

Update a content type

updateContentType mutation in API documentation

mutation UpdateContentType(
  $contentType: ContentTypeUpdateInput!
) {
  updateContentType(
    contentType: $contentType
  ) {
    contentType {
      id
      name
      apiId
      description
    }
    errors {
      key
      message
    }
  }
}

Delete a content type

deleteContentType mutation in API documentation

mutation DeleteContentType(
  $contentTypeName: ProjectContentTypeEnum!
) {
  deleteContentType(
    contentTypeName: $contentTypeName
  ) {
    contentType {
      id
      name
      apiId
    }
    errors {
      key
      message
    }
  }
}

Create a field

createField mutation in API documentation

mutation CreateField(
  $contentTypeId: ID!
  $field: FieldInput!
) {
  createField(
    contentTypeId: $contentTypeId
    field: $field
  ) {
    field {
      id
      label
      apiId
      contentTypeApiId
    }
    errors {
      key
      message
    }
  }
}

Update a field

updateField mutation in API documentation

mutation UpdateField(
  $field: FieldUpdateInput!
) {
  updateField(
    field: $field
  ) {
    field {
      id
      label
    }
    errors {
      key
      message
    }
  }
}

Delete a field

deleteField mutation in API documentation

mutation DeleteField(
  $id: ID!
) {
  deleteField(
    fieldId: $id
  ) {
    field {
      id
      isDeprecated
    }
    errors {
      key
      message
    }
  }
}