Skip to content

Latest commit

 

History

History
174 lines (125 loc) · 3.97 KB

README.rst

File metadata and controls

174 lines (125 loc) · 3.97 KB

Cloudify GraphQL

Documentation Status Updates

Experimental Cloudify GraphQL API

Description

This project is a flask application that implements a GraphQL API that wraps the Cloudify REST API to provide a different way to access data with the benefits of GraphQL. As explained in GraphQL's main page:

  • Ask for what you need, get exactly that
  • Get many resources in a single request

Usage

To give a try to this API, launch a Cloudify manager with its REST API and then the GraphQL API as follows:

FLASK_APP=server.py flask run

Note that for this to work the manager IP address needs to be configured in the GraphQL API application. By default, as it can be seen in config.py, this is set to 172.20.0.2 which is the default IP address of the docker container when running Cloudify through docl.

Once the GraphQL API is running queries can be sent to it using any tool such as curl:

curl -X POST \
    -u admin:admin \
    -H 'Tenant: default_tenant' \
    -H 'Content-Type: application/graphql' \
    http://localhost:5000/graphql \
    -d '{ ping }'

where the Authorization and Tenant headers are passed directly to the Cloudify REST API and are required for authentication purposes.

The GraphiQL tool is also available by opening http://localhost:5000/graphql in a web browser. Note, however, that the browser also needs to send the Authorization and Tenant headers with proper values, so that the GraphQL API can interact successfully with the REST API. To do that, a browser extension such as Modify Header Value can be used. Keep in mind that the Authorization header value can be generated easily with something like:

echo "Basic $(echo -n 'admin:admin' | base64)"

Query Examples

  • Get all tenant names

    {
      tenants {
        name
      }
    }
    
  • Get all blueprints and their deployments

    {
      blueprints {
        id
        deployments {
          id
        }
      }
    }
    
  • Get all deployments and the blueprints they belong to

    {
      deployments {
        id
        blueprint {
          id
        }
      }
    }
    
  • Get all executions and their events and logs

    {
      executions {
        logs {
          message
        }
        events {
          message
        }
      }
    }
    

Mutation Examples

  • Create new tenant

    mutation {
      createTenant(name: "newTenant") {
        statusCode
        tenant {
          name
        }
      }
    }
    
  • Delete tenant

    mutation {
      deleteTenant(name: "newTenant") {
        statusCode
        tenant {
          name
        }
      }
    }
    

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.