GraphQL Plugin API

Table of Contents


Add the interface GraphQLPlugin to your plugin class. You will need to implement the createRootSchema() method to return the object type of your plugin. This type is added to the Gentics Mesh GraphQL API and can be accessed via the pluginApi field.

Each plugin will be added to the pluginApi field using the apiName as the key for the new field:

pluginApi {
    myPluginA {
    myPluginB {
        myField {
The createRootSchema() method will be invoked for every query. It is thus advised to only return GraphQL schema which has been generated up-front.


In the datafetcher which will load the data it is possible to access the context via env.getContext(). This will return a GraphQLPluginContext object that contains methods to access user and other request information.

Table 1. GraphQLPluginContext methods excerpt
Method Description


Name of current project.


Uuid of current project.


Name of current active branch.


Uuid of current active branch.


User information.

.dataFetcher(env -> {
    GraphQLPluginContext ctx = env.getContext();
    // We can check for which project the query was executed
    System.out.println("Project Name: " + ctx.projectName());
    System.out.println("Project Uuid: " + ctx.projectUuid());
    // We can also access the user
    System.out.println("User: " + ctx.principal().encodePrettily());
    return "hello-world";

It is also possible to use the GraphQL SDL to define the schema. The GraphQL Book Library Plugin Example shows how to setup the API using a static schema definition.