Examples of GraphQL requests

October 8, 2024
Note that you need to have the right access and permissions to run these queries.  

Get values of specific properties for a content

The following query get the values of the following properties for a content of type "highlight": title, description and internalLink.

query highlight {
  jcr {
    nodeByPath(
      path: "/sites/digitall/home/area-main/highlights/our-companies"
    ) {
      title: property(language: "en", name: "jcr:title") {
        value
      },
      description: property(language: "en", name: "description") {
        value
      },
      internalLink: property(language: "en", name: "internalLink") {
        value
      }
    }
  }
}

Get rendered HTML for a content 

The following query fetches the rendered HTML for a content, using the view "imgView".

query highlight {
  jcr {
    nodeByPath(
      path: "/sites/digitall/home/area-main/highlights/our-companies"
    ) {
      renderedContent(view: "imgView") {
        output
      }
    }
  }
}

Get all properties for a content

query contentProperties {
  jcr {
    nodeByPath(path: "/sites/digitall") {
      properties {
        name
        value
        values
      }
    }
  }
}

 

Listing the sites with the activated / default languages

query sitesLanguages {
  jcr {
    nodesByPath(paths: ["/sites/"]) {
      children {
        nodes {
          displayName
          defaultLanguage: property(name: "j:defaultLanguage") {
            value
          }
          languages: property(name: "j:languages") {
            values
          }
          inactiveLanguages: property(name: "j:inactiveLanguages") {
            values
          }
          inactiveLiveLanguages: property(name: "j:inactiveLiveLanguages") {
            values
          }
        }
      }
    }
  }
}

 

Counting number of page for a site

This is an example on how to achieve that count with a GraphQL query, note that is is more efficient to use a JCR query to get the same result.

query pagesCount {
  jcr {
    nodeByPath(path: "/sites/digitall") {
      descendants(typesFilter: {types: ["jnt:page"]}) {
        pageInfo {
          totalCount
        }
        nodes {
          type: primaryNodeType {
            name
          }
        }
      }
    }
  }
}

 

List the pages of a site and their vanity URLs

query vanityUrls {
  jcr {
    nodeByPath(path: "/sites/digitall") {
      descendants(fieldFilter: {filters: {evaluation: NOT_EMPTY, fieldName: "node.vanityUrls"}}) {
        nodes {
          node: displayableNode {
            name
            vanityUrls {
              url
            }
          }
        }
      }
    }
  }
}

Editing content (mutation example) and get the modified nodes.

mutation mutationExample {
  jcr {
    mutateNode(pathOrId:"/sites/digitall/home/corporate-responsibility") {
      rename(name:"responsibility")
       mutateProperty(name:"j:published"){
         setValue(type:BOOLEAN,value:"false")
      }
    }
    modifiedNodes {
      path
    }
  }
}

Publish a content

mutation publishContent {
  jcr {
    mutateNode(pathOrId:"/sites/digitall/home/about") {
      publish
    }
  }
}

List of contents that are never been published on a site

query neverPublishedContent {
  jcr {
    nodeByPath(path: "/sites/digitall") {
      descendants(fieldFilter: {filters: {evaluation: EMPTY, fieldName:"published.value"}}) {
        nodes {
          nodeToCheck:
            displayName
            primaryNodeType {
              name
            }
            published:
              property(name:"j:published") {
              value
            }
        }
      }
    }
  }
}

Edit values of osgi configuration files (cfg or yaml)

mutation {
  admin {
    jahia {
      configuration(
        pid: "org.jahia.modules.automatedtags.service.impl.AutomatedTagServiceImpl"
      ) {
        accessKey:value(name:"automated-tags.accessKey",value: "xxxxxx" ),
        secretKey:value(name:"automated-tags.secretKey",value: "yyyyyyy" ),
        endpoint:value(name:"automated-tags.endpoint",value: "https://rekognition.eu-central-1.amazonaws.com" ),
        region:value(name:"automated-tags.region",value: "eu-central-1" ),
        tagImageOnUpload:value(name:"automated-tags.tagImageOnUpload",value: "true" )
      }
    }
  }
}

Get paginated list of editorial contents within a page

This implies that the cursor value of an item is: NTE3ZjE1YmMtZTViYS00YzVkLWIxNmUtMDhiMTgzYTkzMTli To get it, execute the query without the after parameter.


query paginatedContentsWithinApage {
  jcr {
    nodesByPath(paths: ["/sites/digitall/home"]) {
      descendants(first:3 after:"NTE3ZjE1YmMtZTViYS00YzVkLWIxNmUtMDhiMTgzYTkzMTli" typesFilter: {types: ["jmix:editorialContent"], multi: ANY}, recursionTypesFilter: {multi: NONE, types: ["jnt:page", "jnt:contentFolder"]}) {
        edges {
          index
          cursor
          node {
          displayName
          path
          primaryNodeType{
            displayName(language: "en")
          }
        }
        }
      }
    }
  }
}

Get pages tree

query pageTree {
  jcr {
    nodeByPath(path: "/sites/digitall/home") {
      name
      path
      descendants(fieldFilter: {filters: {evaluation: EQUAL, fieldName: "type.name", value: "jnt:page"}}) {
        nodes {
          name
          path 
          type: primaryNodeType {
            name
          }
        }
      }
    }
  }
}

Get content items that were not modified since January 1st 2018

query lastModifiedPages {
  jcr {
    nodesByQuery(query:"SELECT * FROM [jnt:page] as page WHERE page.[jcr:lastModified] >= CAST('2018-01-01T00:00:00.000Z' AS DATE)") {
      edges {
        page: node {
          aggregatedLastModifiedDate
          displayName
          languagesToTranslate
          name
          path
          uuid
          workspace
        }
      }
    }
  }
}