Skip to content

GraphQL

GraphQL is a query language for the API. The GraphQL implementation for Ibexa DXP is located in ibexa/graphql.

Setup

Using GraphQL requires a domain schema. The schema is generated automatically when installing Ibexa DXP.

When you modify content types or product types in your installation, you need to regenerate the schema:

1
2
php bin/console ibexa:graphql:generate-schema
php bin/console cache:clear

YAML files with the schema are located in config/graphql/types/ibexa. They contain information about the domain objects and the fields you can query and operate on.

Schema generation limitations

GraphQL schema cannot be generated for names that don't follow the GraphQL specification, for example names that start with a digit.

This concerns image variations, content types, content type groups, product types, and field definition identifiers.

It's recommended to rename the relevant identifiers. Failure to generate schema is registered in logs. To find identifiers that aren't included in the schema, look for "Skipped schema generation" log messages, for example: Skipped schema generation for Image Variation.

Domain schema

GraphQL for Ibexa DXP is based on the content types (including product types), content type groups, and content items defined in the repository.

For each content type the schema exposes a singular and plural field, for example, article and articles. Use the singular field to query a single content item, and the plural to get a whole Connection (a list of content items that supports pagination).

With the queries you can inspect:

  • the existing types
  • details of content types, and their fields in the context of developing your own application

You can request additional content information such as the section or Objects states, available under the _info field.

You can also query content type and content type group information through the _info and _types fields.

Repository schema

The repository schema, accessed through _repository, exposes the Ibexa DXP repository in a manner similar to the Public PHP API.

The _repository field also enables you to query, for example, object states configured for the repository.

Custom schemas

You can also use your own custom schema.

SiteAccesses and multiple Repositories

GraphQL is SiteAccess-aware, but can have only one schema per installation. This means you cannot use GraphQL with multiple repositories.

When you request a URL from a SiteAccess that is different than the current one, the API generates it for the content item's SiteAccess, with an absolute URL if necessary.

Authentication

GraphQL for Ibexa DXP supports session-based authentication. You can get your session cookie by logging in through the interface or through a REST request.

JWT authentication

If you have JWT authentication enabled, you can use the following query to get your authentication token:

1
2
3
4
5
6
mutation CreateToken {
  createToken(username: "admin", password: "publish") {
    token
    message
  }
}

Response:

1
2
3
4
5
6
7
8
{
  "data": {
    "createToken": {
      "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MDI4MzU5MTksImV4cCI6MTYwMjgzOTUxOSwicm9sZXMiOlsiUk9MRV9VU0VSIl0sInVzZXJuYW1lIjoiYWRtaW4ifQ.QtDjPU6q68fdvgm6O_1-aEoe-s7s-VQr-9CTMC9ba6E",
      "message": null
    }
  }
}

Usage

You can access GraphQL with <yourdomain>/graphql.

GraphiQL client

The GraphiQL interactive client is included in the installation. Access it through <yourdomain>/graphiql.

Here you can run your queries and preview the results in a readable format.

Reference

GraphiQL offers side-by-side reference based on your generated schema in the Docs pane.