10 examples of GraphQL requests

  Written by The Jahia Team
 
Developers
   Estimated reading time:
Note that you need to have the right access and permissions to run these queries.  

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

Get all properties for a content

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

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