How it works: CMCI GraphQL API

The CICS management client interface (CMCI) provides a GraphQL application programming interface (API) for system management clients such as IBM® CICS Explorer®. The CMCI GraphQL API is supported through HTTP. With the GraphQL API, a client can query many types of CICS® resources across CICSplexes in a single request. In the single query request, the client can specify exactly what data it needs about multiple CICS resources, with explicitly expressed inherent relationships between the CICS resources.

The aggregation function in CICS Explorer 5.5 requires the CMCI GraphQL API. The CMCI GraphQL API requires the CMCI JVM server to be used with the CMCI. For more information about GraphQL, see Introduction to GraphQL.

What is a GraphQL query?

A simple GraphQL query request looks like this:
Figure 1. Simple query requesting CICSplex names
{
  cicsplexes {
    name
  }
}

At the root of the query is the cicsplexes field, which finds all the CICSplexes that the WUI server is connected to. The name field nested in the cicsplexes field requests the name of each CICSplex.

Query responses are returned as JSON objects, with the requested data enclosed in the value of the data field. The structure of the response follows that in the query.
Figure 2. Response to simple query about CICSplex names
{
  "data": {
    "cicsplexes": [
      {
        "name": "CICSPLX01"
      },
      {
        "name": "CICSPLX02"
      }
    ]
  }
}

To retrieve more information, add more fields to the query, including nested ones. See Sample queries.

How to make GraphQL API requests

The GraphQL API endpoint is at:
https://host:port/graphql
where host and port are the host name and the port number of your CMCI JVM server.
The GraphQL API accepts GET and POST requests.
For GET requests:

A Content-Type: application/json header must be sent. The query is supplied by the query query parameter. The operation is supplied by the optional operationName query parameter.

For example, the simple query in Figure 1 can be sent by using the following URL:
https://host:port/graphql?query={cicsplexes{name}}
For POST requests:
A Content-Type: application/json header must be sent. The body of the request must be a JSON-encoded object.
{
    "query": "query_body",
    "operationName": "operation_name"
}
where only the query field is mandatory.

Alternatively, a Content-Type: application/graphql header can be sent on POST requests. In this case, the body of the request must be the GraphQL query itself, and no operation name can be specified.

See Sample queries for sample code of GraphQL queries.

Sample queries

You can use GraphiQL, an online GraphQL visualization editor, to test your GraphQL queries or the samples. The URL to GraphiQL is:
https://host:port/graphiql
where host and port are the host name and the port number of your CMCI JVM server.
GraphiQL tips:
  • GraphiQL provides auto-completion and a built-in documentation explorer for GraphQL schema reference. You can display available field names by pressing Ctrl+Space.
  • To easily differentiate queries in GraphiQL history, you can specify a unique query name by prefixing the query with query QueryName.
The following example queries the count of local files of all regions in all the connected CICSplexes, and the name of each CICSplex and region. It also has a query name LocalFilesInRegionsInCICSplexes.
query LocalFilesInRegionsInCICSplexes {
  cicsplexes {
    name
    regions {
      name
      cicsResources {
        locfile {
          count
        }
      }
    }
  }
}
You can add more attributes to be queried. This example queries all CICSplexes and all the regions in each CICSplex. Within each region, it retrieves the name, useCount, and status fields of all the local transactions.
{
  cicsplexes {
    name
    regions {
      name
      cicsResources {
        loctran {
          records {
            name
            useCount
            status
          }
        }
      }
    }
  }
}
You can specify which CICSplex or CICS region to be queried. This example queries Region AORRGN in CICSplex PLEX1, retrieving the name, useCount, and status fields of all the local transactions in the region.
{
  cicsplex(name: "PLEX1") {
    name
    region(name: "AORRGN") {
      name
      cicsResources {
        loctran {
          records {
            name
            useCount
            status
          }
        }
      }
    }
  }
}
Removing the CICSplex and region specifications, this example queries all connected CICSplexes and the name, useCount, and status fields of all the local transactions in those CICSplexes.
{
  cicsplexes {
    name
    cicsResources {
      loctran {
        records {
          name
          useCount
          status
        }
      }
    }
  }
}
This example is similar to the previous one, except that it uses a filter to retrieve only transactions starting with CED.
{
  cicsplexes {
    name
    cicsResources {
      loctran(filter: {name: {value: "CED*"}}) {
        records {
          name
          useCount
          status
        }
      }
    }
  }
}
You can also query CICS definitions. This request queries the name and update attributes for all file definitions in the CICSplex data repository.
{
  cicsplex(name: "PLEX1") {
    drep {
      cicsDefinitions {
        filedef {
          records {
            name
            update
          }
        }
      }
    }
  }
}
Similarly, this request queries the name for all pipeline definitions in the CSD for Region AORRGN in CICSplex PLEX1.
{
  cicsplex(name: "PLEX1") {
    region(name: "AORRGN") {
      csd {
        cicsDefinitions {
          pipedef {
            records {
              name
            }
          }
        }
      }
    }
  }
}
This query performs aggregation of all local files in each CICSplex, grouping them by common values of the name attribute and retrieving the count of aggregated records within each aggregation group, the name of each group, and the average, minimum, and maximum readCount within each group.
{
  cicsplexes {
    name
    cicsResources {
      locfile {
        groupBy(attribute: "name") {
          count
          aggregateRecord {
            name {
              value
            }
            readCount {
              average
              min
              max
            }
          }
        }
      }
    }
  }
}