> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/mutations/updatedatatype.md).

# Update Data Type

Update DataType Mutation

Updates an existing data type definition in the system.

## Arguments

| Name    | Type                   | Description                           |
| ------- | ---------------------- | ------------------------------------- |
| `id`    | `ID!`                  | The ID of the data type to update     |
| `input` | `UpdateDataTypeInput!` | Input data for updating the data type |

## Return Type

`DataType` - The updated data type object.

## Input Fields

`UpdateDataTypeInput`:

| Field                 | Type      | Description                           |
| --------------------- | --------- | ------------------------------------- |
| `name`                | `String`  | Name of the data type                 |
| `description`         | `String`  | Optional description of the data type |
| `clearDescription`    | `Boolean` | Clear the description field           |
| `jsonSchema`          | `String`  | JSON schema definition                |
| `frontendSchema`      | `String`  | Optional frontend schema definition   |
| `clearFrontendSchema` | `Boolean` | Clear the frontend schema field       |

## Usage Example

```graphql
mutation {
  updateDataType(
    id: "dt_123456789"
    input: {
      name: "Enhanced Customer Profile"
      description: "Updated customer data type with additional fields for loyalty and preferences"
      jsonSchema: "{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\",\"minLength\":1},\"email\":{\"type\":\"string\",\"format\":\"email\"},\"phone\":{\"type\":\"string\"},\"address\":{\"type\":\"object\",\"properties\":{\"street\":{\"type\":\"string\"},\"city\":{\"type\":\"string\"},\"state\":{\"type\":\"string\"},\"zip\":{\"type\":\"string\"},\"country\":{\"type\":\"string\"}}},\"loyaltyTier\":{\"type\":\"string\",\"enum\":[\"bronze\",\"silver\",\"gold\",\"platinum\"]},\"preferences\":{\"type\":\"object\",\"properties\":{\"language\":{\"type\":\"string\"},\"currency\":{\"type\":\"string\"},\"timezone\":{\"type\":\"string\"}}}},\"required\":[\"name\",\"email\"]}"
      frontendSchema: "{\"fields\":[{\"name\":\"name\",\"type\":\"text\",\"label\":\"Full Name\",\"required\":true},{\"name\":\"email\",\"type\":\"email\",\"label\":\"Email Address\",\"required\":true},{\"name\":\"phone\",\"type\":\"tel\",\"label\":\"Phone Number\"},{\"name\":\"loyaltyTier\",\"type\":\"select\",\"label\":\"Loyalty Tier\",\"options\":[\"bronze\",\"silver\",\"gold\",\"platinum\"]}]}"
    }
  ) {
    id
    name
    description
    jsonSchema
    frontendSchema
    updatedAt
  }
}
```

```graphql
mutation {
  # Update schema to add new validation rules
  updateDataType(
    id: "dt_inventory_item"
    input: {
      jsonSchema: "{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200},\"sku\":{\"type\":\"string\",\"pattern\":\"^[A-Z0-9-]+$\"},\"description\":{\"type\":\"string\",\"maxLength\":1000},\"weight\":{\"type\":\"number\",\"minimum\":0},\"dimensions\":{\"type\":\"object\",\"properties\":{\"length\":{\"type\":\"number\",\"minimum\":0},\"width\":{\"type\":\"number\",\"minimum\":0},\"height\":{\"type\":\"number\",\"minimum\":0}},\"required\":[\"length\",\"width\",\"height\"]},\"category\":{\"type\":\"string\"},\"tags\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}},\"hazardous\":{\"type\":\"boolean\",\"default\":false},\"perishable\":{\"type\":\"boolean\",\"default\":false},\"serialTracked\":{\"type\":\"boolean\",\"default\":false}},\"required\":[\"name\",\"sku\"]}"
    }
  ) {
    id
    jsonSchema
    updatedAt
  }
}
```

```graphql
mutation {
  # Clear frontend schema and update description
  updateDataType(
    id: "dt_supplier_basic"
    input: {
      description: "Basic supplier information without advanced features"
      clearFrontendSchema: true
    }
  ) {
    id
    description
    frontendSchema
    updatedAt
  }
}
```

## Update Strategies

### Schema Evolution

When updating JSON schemas, consider:

* **Backward Compatibility**: Ensure existing data remains valid
* **Field Addition**: New optional fields are safe to add
* **Field Removal**: Removing fields may break existing data
* **Validation Changes**: Stricter validation may invalidate existing records

### Frontend Schema Updates

The `frontendSchema` field provides UI hints for form generation:

* Update field types and labels
* Add new form fields for new schema properties
* Remove obsolete UI elements
* Update validation rules and help text

### Field Clearing

Use clear flags to remove optional fields:

* `clearDescription: true` - Removes the description
* `clearFrontendSchema: true` - Removes the frontend schema

## Common Update Scenarios

### Schema Enhancement

* Add new optional fields to accommodate evolving business needs
* Update validation rules to enforce data quality
* Modify field types to support new data formats
* Add enum values for new category options

### UI Improvements

* Update frontend schema to improve form usability
* Add better field labels and help text
* Reorganize field order for better user experience
* Add conditional field visibility rules

### Maintenance Updates

* Fix validation issues in existing schemas
* Update descriptions for better documentation
* Align schemas with current business processes
* Remove deprecated fields and constraints

## Validation Considerations

### JSON Schema Validation

* Ensure the JSON schema is syntactically valid
* Test schema against existing data before updating
* Consider migration path for existing records
* Document breaking changes for dependent systems

### Impact Assessment

Before updating a data type:

* Identify entities using this data type
* Check for data compatibility issues
* Plan data migration if needed
* Notify affected users and systems

## Best Practices

1. **Version Control**: Keep track of schema changes over time
2. **Testing**: Validate new schemas against sample data
3. **Documentation**: Update descriptions to reflect changes
4. **Communication**: Notify stakeholders of significant changes
5. **Rollback Plan**: Have a plan to revert problematic changes
6. **Gradual Updates**: Make incremental changes rather than major overhauls

## Error Handling

Updates may fail due to:

* **Invalid JSON**: Malformed JSON schema syntax
* **Schema Conflicts**: New schema incompatible with existing data
* **Permission Issues**: Insufficient rights to modify data types
* **Dependency Violations**: Other systems depend on current schema structure

## Notes

* Schema changes affect all entities using this data type
* Consider creating new data types instead of modifying critical existing ones
* Test schema changes in development environments first
* Monitor system performance after schema updates
* Keep backup copies of working schemas before making changes


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/mutations/updatedatatype.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
