Manage Enums

Introduction

Enums can be created and assigned to fields to allow for a strict set of values to be applied. Enums on a version can be managed with the editEnumConfiguration mutation.

If you try to create with a name that already exists an error will be thrown, however if you create an enum as part of a new draft, then create the enum again in the same draft; the original enum will be updated.

Enums and their values will be converted into enum convention styling. Specifically:

  • Enum names supplied in snake case will be configured into upper camel case: some_new_enum
  • Enum values will be converted to upper case

πŸ“˜

IMPORTANT

Upon completion of any of the queries listed below, it will be necessary to activate the new version you have created using this query.

Create A New Enum

mutation MyMutation {
  editEnumConfiguration(
    version: 2, 
    enums: [
      {
        name: "MyNewEnum", 
        values: ["VALUE_1", "VALUE_2"], 
        operation: CREATE
      },
      {
        name: "another_new_enum", 
        values: ["lower_case_value", "ANOTHER_VALUE"], 
        operation: CREATE
      }
    ]
  ) {
    version
    messages
  }
}

Response:

πŸ“˜

Note the format changes of the enum name and values!

{
  "data": {
    "editEnumConfiguration": {
      "version": 2,
      "messages": [
        "Updated draft version 2",
        "Created enum: MyNewEnum",
        "Added value VALUE_1 to enum MyNewEnum",
        "Added value VALUE_2 to enum MyNewEnum",
        "Created enum: AnotherNewEnum",
        "Added value LOWER_CASE_VALUE to enum AnotherNewEnum",
        "Added value ANOTHER_VALUE to enum AnotherNewEnum"
      ]
    }
  }
}

Update Existing Enums

mutation MyMutation {
  editEnumConfiguration(
    version: 2, 
    enums: [
      {
        name: "MyExistingEnum", 
        values: ["VALUE_1", "VALUE_2"], 
        operation: UPDATE
      }
    ]
  ) {
    version
    messages
  }
}

Response:

{
  "data": {
    "editEnumConfiguration": {
      "version": 2,
      "messages": [
        "Version 2 not found. Creating new version (2) based on active version.",
        "Updated enum: MyExistingEnum",
        "Added value VALUE_1 to enum MyExistingEnum",
        "Added value VALUE_2 to enum MyExistingEnum"
      ]
    }
  }
}

❗️

Please note!

An update here acts like a PUT command, meaning you will need to include any existing enums associated with this TYPE that you want to keep when you update. Any Enums not specified in the request will be removed as part of the execution of this query.

Find Existing Enums and Values

You can find all the existing enums by inspecting a given version of your schema. Find out more here.