Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Support for GraphQL with Open Liberty 20.0.0.6

 

June 17, 2020
yasmin-aumeeruddy
Related topics:
DevOpsJavaKubernetesMicroservices
Related products:
Developer Tools

Share:

    The Open Liberty 20.0.0.6 release brings new features, updates, and bug fixes. This article introduces the new features in Open Liberty 20.0.0.6, including support for developing "code-first" GraphQL applications, provisioning features from a Maven repository, and using a server configuration to control application startup.

    What's new in Open Liberty 20.0.0.6

    Open Liberty 20.0.0.6 includes the following feature updates, which I discuss in the next sections:

    • Using GraphQL with Open Liberty
    • Provisioning features from a Maven repository
    • Administrators control the application start order
    • New REST visualizations in Open Liberty Grafana dashboards
    • Web application startup changes

    Note: Visit Open Liberty's GitHub repository to learn about bug fixes in Open Liberty 20.0.0.6.

    Run your apps using Open Liberty 20.0.0.6

    Use the following command to get or update to Open Liberty 20.0.0.6 using Maven:

      <dependency>
          <groupId>io.openliberty</groupId>
          <artifactId>openliberty-runtime</artifactId>
          <version>20.0.0.6</version>
          <type>zip</type>
      </dependency>
    

    If you're using Gradle, simply enter:

    dependencies {
        libertyRuntime group: 'io.openliberty', name: 'openliberty-runtime', version: '[20.0.0.6,)'
    }
    

    Here's the command for Docker:

    FROM open-liberty
    

    See the Open Liberty downloads page to get the latest release for Jakarta EE 8, Web Profile 8, and MicroProfile 3.

    Using GraphQL with Open Liberty

    Open Liberty's support for MicroProfile GraphQL lets developers write "code-first" GraphQL applications that put clients in control of the data they receive. You can use annotations like @Query and @Mutation to turn Plain Old Java Objects (POJOs) into HTTP-based GraphQL endpoints. When the query or mutation method returns an existing entity object, the client can specify the fields it is interested in—which reduces network bandwidth and client-side processing.

    Here’s an example:

    @GraphQLApi
    public class MovieService {
        AtomicInteger nextId = new AtomicInteger();
        Map<Integer, Movie> movieDB = new HashMap();
    
        @Query("movieById")
        public Movie getMovieByID(int id) throws UnknownMovieException {
            return Optional.ofNullable(movieDB.get(id)).orElseThrow(UnknownMovieException::new);
        }
    
        @Query("allMoviesDirectedBy")
        public List<Movie> getAllMoviesWithDirector(String directorName) {
            return movieDB.values().stream()
                                   .filter(m -> m.getDirector().equals(directorName))
                                   .collect(Collectors.toList());
        }
    
        @Mutation("newMovie")
        public int createNewMovie(@Name("movie") Movie movie) {
            int id = nextId.incrementAndGet();
            movie.setId(id);
            movieDB.put(id, movie);
            return id;
        }
    }
    

    This code creates a GraphQL application with two queries (movieById and allMoviesDirectedBy) and a mutation (newMovie). If the client executes the following query:

    query {
      allMoviesDirectedBy(directorName: "Roland Emmerich") {
        id, title, actors
      }
    }
    

    The result will be:

    {
      "data": {
        "allMoviesDirectedBy": [
          {
            "id": 1,
            "title": "Independence Day",
            "actors": [
              "Will Smith",
              "Bill Pullman",
              "Jeff Goldblum",
              ...
            ]
          },
          ...
        ]
      }
    }
    

    Open Liberty’s GraphQL APIs were developed within the MicroProfile community and have broad industry support. The implementation is based on SmallRye GraphQL. Liberty’s GraphQL feature goes beyond the MicroProfile specification and adds support for collecting metrics, checking authorizations, and logging requests and responses to query and mutation methods.

    For more details and a sample application, see this simple demo of the MicroProfile GraphQL capabilities in Open Liberty. Join the growing landscape of GraphQL adopters and write your first GraphQL application today!

    Provisioning features from a Maven repository

    Developers can now use a convenient command-line tool to install features from the Maven Central repository or an on-premises Maven repository (such as one served on Artifactory or Nexus) directly onto an Open Liberty runtime. Table 1 details using the wlp/bin/featureUtility commands to find, install, and get information about assets in a Maven repository.

    Table 1. Open Liberty commands to install features from a Maven repository

    Command Description
    featureUtility help installFeature Display help information for the installFeature action.
    featureUtility installFeature mpHealth-2.2 or featureUtility installFeature io.openliberty.features:mpHealth-2.2 Install the MicroProfile Health 2.2 feature from Maven Central.
    featureUtility installServerFeatures myserver Install server features for the myserver server.
    featureUtility installFeature mpHealth-2.2 --noCache Install the MicroProfile Health 2.2 feature without caching the feature to the local Maven repository.
    featureUtility installServerFeatures myserver --noCache Install server features for the myserver server without caching the features to the local Maven repository.
    featureUtility installFeature adminCenter-1.0 --acceptLicense Install the Admin Center feature from Maven Central.
    featureUtility installServerFeatures defaultServer --verbose Install features for the myserver server with debugging enabled.
    featureUtility viewSettings View a template of your featureUtility.properties file.
    featureUtility find mpHealth-2.2 Search for the MicroProfile Health 2.2 feature from Maven Central and all configured Maven repositories.
    featureUtility find Search for all available features from Maven Central and all configured Maven repositories.

    Administrators control the application start order

    By default, applications start in parallel and can finish starting in random order. With the 20.0.0.6 release, Open Liberty empowers administrators to prevent an application from starting until one or more other applications have started.

    Being able to define the order of application startup is critical because applications are often dependent on each other. For example, a single Open Liberty server might contain a front-end application that provides a user interface and a back-end application that accesses a database. Having the front-end application available before the back end started could result in errors. With this feature, you could prevent the front-end application from starting until the back end was ready.

    You only need to define the application dependencies in the configuration, using the startAfter attribute on the application element. In this example, you would add a comma-separated list of ID values for the back-end applications that must start before the front-end application can run:

     <webApplication id="frontend" location="myFrontend.war" startAfter="backend1, backend2"/>
     <enterpriseApplication id="backend1" location="myBackend.ear"/>
     <enterpriseApplication id="backend2" location="myUtilities.ear"/>
    

    REST visualizations in Open Liberty Grafana dashboards

    Grafana dashboards provide a wide range of time-series visualizations of MicroProfile Metrics data such as CPU, REST, servlet, connection pool, and garbage collection metrics. Grafana dashboards are powered by a Prometheus data source, which is configured to ingest data from the /metrics endpoint of one or more Open Liberty servers. As a result, users can view the metrics on Grafana dashboards in near real-time.

    With the release of mpMetrics-2.3 and its addition of JAX-RS metrics, we've introduced a new set of visualizations to our Open Liberty Grafana dashboards. You can find these under a new tab labeled REST. We've also added hover-over descriptions that provide a brief summary of each visualization and its function. These updates apply to OKD 3.11 (the upstream distribution of Red Hat OpenShift), Red Hat OpenShift Container Platform (OCP), and standalone Open Liberty instances.

    If you do not already have Grafana and Prometheus set up in your development environment, see the Kabanero guide for Red Hat OpenShift Container Platform 4.3. To get started using the Grafana dashboard with Open Liberty, see my blog post introducing Open Liberty's support for MicroProfile 3.3.

    Note: You can find the Grafana dashboards for Open Liberty on OKD or OCP in the open-liberty-operator repository.

    Web application startup changes

    Starting with Open Liberty 20.0.0.6, web applications are considered started only after calls to ServletContainerInitializers and ServletContextListeners have completed. This update effectively moves more of the application initialization process into the server-startup route. As a result, it might appear that applications and the server take longer to start. The change doesn't affect how long it takes for applications to begin processing requests; it just moves it to run prior to the opening of the ports. In addition, you can now configure the server.xml so that a failure in a ServletContextListener will cause application startup to fail. Just add the following:

    <webContainer stopAppStartUponListenerException="true"/>
    

    Note: Find out more about application properties here.

    Conclusion

    Open Liberty 20.0.0.6 is available through Maven, Gradle, Docker, and as a downloadable archive. Get it today to begin using the new features I've described in this article.

    Last updated: February 13, 2024

    Recent Posts

    • AI meets containers: My first step into Podman AI Lab

    • Live migrating VMs with OpenShift Virtualization

    • Storage considerations for OpenShift Virtualization

    • Upgrade from OpenShift Service Mesh 2.6 to 3.0 with Kiali

    • EE Builder with Ansible Automation Platform on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue