Skip to main content

findOrCreateCategory

Requires permission categories:category:create.

Returns the category with this name, matched without regard to case, or creates it when none exists. A new category is active, sits at the top level and gets a generated code. An empty name is refused. Requires permission to create categories.

Errors: a failed call returns a GraphQL errors entry, not a field on the result, and data may be null or partial. Read the entry's extensions.code and message; every shape and code is in the Error reference.

Example:

mutation FindOrCreateCategory($name: String!) {
findOrCreateCategory(name: $name) {
id
code
name
createdAt
childrenCount
deletedAt
children {
id
code
name
createdAt
childrenCount
deletedAt
}
}
}

Variables:

{
"name": "string"
}

Response:

{
"data": {
"findOrCreateCategory": {
"id": "id",
"code": "string",
"name": "string",
"createdAt": "2025-01-15T00:00:00Z",
"childrenCount": 0,
"deletedAt": "2025-01-15T00:00:00Z",
"children": [
{
"id": "id",
"code": "string",
"name": "string",
"createdAt": "2025-01-15T00:00:00Z",
"childrenCount": 0,
"deletedAt": "2025-01-15T00:00:00Z"
}
]
}
}
}
findOrCreateCategory(
name: String!
): Category!

Arguments​

findOrCreateCategory.name ● String! non-null scalar​

The category name. Leading and trailing spaces are ignored.

Type​

Category object​

A node in the category tree. A root category is an ordinary category.