Blogs

Blogs

New GraphQL APIs in Liferay 7.2

All the power of relationships, now in your apps!

Liferay 7.2 GA2 brings us many awesome new features but I'm particularly proud of one: GraphQL support.

Starting today you can build dynamic JS applications with your preferred framework (which is the one trending today?) and leverage the powerful GraphQL queries to fill the entire screen with one request.

In 7.2 we introduced the new breed of Headless APIs to help you serve your clients better. And in this release, we complement it with all these features, over GraphQL. And it's also available in 7.1 in the latest fixpacks.

How can I try them?

Just access the new endpoint, localhost:8080/o/graphql, with your GraphQL viewer. We recommend Altair, a Chrome extension, but a GraphiQL instance will also work well. That way you can see all the endpoints and add queries directly:

 

What are the main features?

It's a full-fledged GraphQL implementation and it has feature parity with the REST APIs. So you can expect everything that the new Headless REST APIs support (pagination, filter, search, sort, flatten, sparse fieldsets, just to mention a few).

But it also brings us some new goodies... the main one is relationships! You can avoid several HTTP requests by querying for related fields, like MBMessages or Ratings inside an MBThread:

query {
  messageBoardThreads(siteKey: "Guest") {
    items {
      aggregateRating {
        ratingCount
        ratingValue
      }
      articleBody
      id
      messageBoardMessages {
        items {
          headline
        }
      }
    }
    page
    pageSize
    totalCount
  }
}

Relations are the reason GraphQL is popular and having them available in your javascript app can heavily simplify the work of frontend developers.

Our GraphQL implementation also supports interfaces (with generics!), fragments, node pattern, deals with versioning... you have to check it out!

How can the GraphQL APIs help me?

GraphQL shines when you want to minify the number of requests you need to execute from your frontend, either because of complexity (Android & iOS apps) or size (JS frontend).

If you are already used to GraphQL, familiarity can be another reason to adopt it. If you like pre-defined schemas with strong types in your APIs, this is the right fit :)

How can I know more?

Check out these sample applications or read the (beta) documentation. Or ask us on slack!

We are expectant to receive your feedback and ideas to improve it even further!

It looks great, well done! Are there any documentation to create GraphQL API from backend from custom entities or whatever?

 

Thanks!