Rubrik GraphQL API

GraphQL is an API query language that allows you to retrieve just the data you need. GraphQL eliminates the common experience of an API call returning either too much or not enough data.

GraphQL queries are defined in terms of types and fields. Rather than using various endpoints identified by path-based URIs and HTTP verbs, GraphQL uses a single endpoint backed by a schema that specifies how to retrieve and modify application data based on the relationship between the types and fields.

You can use GraphQL queries to retrieve data, and mutations to modify data. A GraphQL query is a request to retrieve specific fields of an object type, and a GraphQL mutation is a request to modify specific fields of an object type. The GraphQL runtime engine validates the incoming queries and mutations against the schema and fulfils the valid requests.

Every GraphQL service has a Query type, and may also have a Mutation type. The Query and Mutation types are special object types in the schema, as they serve as entry points to the API.

GraphQL query type

type Query {
    # Retrieves the user that is currently logged-in
    currentUser: User!

    # Retrieves the user with the specified user ID
    user(userId: UUID!): User!
}

In the above example, the Query object type has two fields: currentUser and user. This implies that the above schema supports the following types of requests:

A GraphQL query with either of these fields returns an object of type User:

type User {
    # User ID
    userID: UUID!

    # User name
    email: String!

    # Roles that the user has
    roles: [String!]!
}

Based on the definition of the User object type, you can define the fields to be selected from the User object that is returned by the query.

The following example provides a sample query and response based on the above schema definition.

Sample GraphQL query Sample response


query {
    currentUser {
        email
        roles {
            name
        }
    }
}


{
  "data": {
    "currentUser": {
      "email": "happy.user@rubrik.com",
      "roles": [
        {
          "name": "Administrator",
        }
      ],
    }
  },
}

More information on GraphQL queries and mutations available on graphql.org.