### Install @hygraph/management-sdk Source: https://github.com/hygraph/management-sdk/blob/main/README.md Install the management SDK as a development dependency using npm. ```bash npm install @hygraph/management-sdk --save-dev ``` -------------------------------- ### Create Model Source: https://github.com/hygraph/management-sdk/blob/main/README.md Define a new model in your Hygraph schema. Ensure 'apiId' and 'apiIdPlural' start with an uppercase letter. ```javascript const modelName = migration.createModel({ apiId, // must start with upper case letter apiIdPlural, // must start with upper case letter displayName, description, }); ``` -------------------------------- ### Manage Models and Add Fields Source: https://context7.com/hygraph/management-sdk/llms.txt Create, update, or delete content models and chain field additions. Model API IDs and plural IDs must start with an uppercase letter. Use `FieldType` enum for field types. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); // Create a model and immediately add fields const product = migration.createModel({ apiId: "Product", apiIdPlural: "Products", displayName: "Product", description: "A store product", }); product .addSimpleField({ apiId: "name", displayName: "Name", type: FieldType.String, isRequired: true }) .addSimpleField({ apiId: "price", displayName: "Price", type: FieldType.Float }) .addSimpleField({ apiId: "inStock", displayName: "In Stock", type: FieldType.Boolean }) .addSimpleField({ apiId: "publishedAt", displayName: "Published At",type: FieldType.DateTime }); // Update an existing model's display name migration.updateModel({ apiId: "Product", displayName: "Store Product" }); // Delete a model migration.deleteModel("OldModel"); await migration.run(true); ``` -------------------------------- ### Create a Migration Instance Source: https://context7.com/hygraph/management-sdk/llms.txt Instantiate a new migration object with environment configuration. Requires an endpoint URL and auth token. The migration instance can only be run once. ```javascript const { newMigration, FieldType, RelationType, Renderer } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "https://api-eu-central-1.hygraph.com/v2/clxxxxxx/master", authToken: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", name: "add-blog-schema-v1", // optional; must be unique per environment }); ``` -------------------------------- ### Initialize a New Migration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Initialize a new migration instance with authentication token and environment endpoint. An optional migration name can also be provided. ```javascript const { newMigration } = require("@hygraph/management-sdk"); const migration = newMigration({ authToken, endpoint, name, // optional }); ``` -------------------------------- ### Run a Hygraph Migration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Execute the migration. Pass `true` to run in the foreground and receive immediate results, or omit for background execution. Check the result for errors. ```javascript const foreground = true; const result = migration.run(foreground); if (result.errors) { console.log(result.errors); } else { console.log(result.name); } ``` -------------------------------- ### Initialize Migration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Initializes a new migration instance with authentication and endpoint details. Optionally, a migration name can be provided. ```APIDOC ## Initialize Migration A migration is scoped to an environment. To create a migration, the following parameters are required. - **Authentication Token `authToken`** Can be retrieved from `Settings > API Access` on https://app.hygraph.com - **Environment URL `endpoint`** Can be retrieved from `Settings > Environments` on https://app.hygraph.com - **Migration Name `name` [optional]** Every migration has a unique name. If unspecified, a name would be generated and will be part of the response of a successful migration. Subsequent migrations with same name will fail. ```js const { newMigration } = require("@hygraph/management-sdk"); const migration = newMigration({ authToken, endpoint, name, // optional }); ``` ``` -------------------------------- ### Running a Migration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Executes the defined migration. It can be run in the foreground by passing `true` as an argument, which returns the result directly. ```APIDOC ## Running a Migration The `run` method runs the migration. By default, migrations run in the background. Passing an optional boolean argument configures the migration to run in the foreground. ```js const foreground = true; const result = migration.run(foreground); if (result.errors) { console.log(result.errors); } else { console.log(result.name); } ``` ``` -------------------------------- ### migration.run(foreground?) Source: https://context7.com/hygraph/management-sdk/llms.txt Submits all queued schema changes to Hygraph. Can run in the background (default) or foreground (blocking). Returns MigrationInfo or throws an error. ```APIDOC ## migration.run(foreground?) ### Description Submits all queued changes to Hygraph. By default runs in the background and returns a `MigrationInfo` with `id`, `status`, and `name`. Pass `true` to run in the foreground and block until the migration finishes (or fails). Throws if called a second time on the same instance. ### Parameters #### Path Parameters - **foreground** (boolean) - Optional - If `true`, runs the migration in the foreground and waits for completion. ### Response #### Success Response (200) - **MigrationInfo** (object) - Contains `id`, `status`, and `name` of the migration. ### Request Example ```js async function runMigration() { const migration = newMigration({ endpoint: "https://api-eu-central-1.hygraph.com/v2/clxxxxxx/master", authToken: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", }); migration.createModel({ apiId: "Post", apiIdPlural: "Posts", displayName: "Post", }); // Foreground: waits for completion const result = await migration.run(true); if (result.errors) { console.error("Migration failed:", result.errors); } else { console.log("Migration succeeded:", result.name); } } runMigration(); ``` ``` -------------------------------- ### Create Stage Source: https://github.com/hygraph/management-sdk/blob/main/README.md Creates a new content stage with properties like API ID, display name, description, default status, query permissions, and color. ```APIDOC ## Create a Stage To create a stage ```js migration.createStage({ apiId, displayName, description, isDefault, allowQueries, color, }); ``` ``` -------------------------------- ### Create a New Hygraph Model and Fields Source: https://github.com/hygraph/management-sdk/blob/main/README.md Use this snippet to initialize a new migration and define a new model with simple string fields. Ensure you have your Hygraph endpoint and authentication token. ```javascript const { newMigration, FieldType } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); const author = migration.createModel({ apiId: "Author", apiIdPlural: "Authors", displayName: "Author", }); author.addSimpleField({ apiId: "firstName", displayName: "First Name", type: FieldType.String, }); author.addSimpleField({ apiId: "lastName", displayName: "Last Name", type: FieldType.String, }); migration.run(); ``` -------------------------------- ### Create Enumeration with Values Source: https://github.com/hygraph/management-sdk/blob/main/README.md Use this to create a new enumeration with initial values. Values can be added individually or in batches. ```javascript const colors = migration.createEnumeration({ apiId, displayName, description, }); // add values colors.addValue("Red"); colors.addValue("Green"); // or add multiple values at a time. colors.addValue("Blue", "Yellow"); ``` -------------------------------- ### Dry Run a Hygraph Migration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Preview the changes that a migration would apply without actually executing them. This is useful for verifying the migration plan. ```javascript const changes = migration.dryRun(); console.log(changes); ``` -------------------------------- ### newMigration(config) Source: https://context7.com/hygraph/management-sdk/llms.txt Creates a new Migration object for a specific Hygraph environment. Requires an environment endpoint URL and a permanent auth token. An optional unique name can be provided. ```APIDOC ## newMigration(config) ### Description Creates and returns a new `Migration` object scoped to a specific Hygraph environment. Requires an environment endpoint URL and a permanent auth token. An optional `name` can be given; if omitted, a unique name is auto-generated. Each migration instance can only be run once. ### Parameters #### Path Parameters - **config** (object) - Required - Configuration object containing: - **endpoint** (string) - Required - The Hygraph environment endpoint URL. - **authToken** (string) - Required - A permanent auth token for the environment. - **name** (string) - Optional - A unique name for the migration. ### Request Example ```js const { newMigration } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "https://api-eu-central-1.hygraph.com/v2/clxxxxxx/master", authToken: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", name: "add-blog-schema-v1", // optional; must be unique per environment }); ``` ``` -------------------------------- ### Execute a Migration (Foreground) Source: https://context7.com/hygraph/management-sdk/llms.txt Submits queued schema changes to Hygraph and waits for completion. Returns migration details or throws an error if the migration fails. This method can only be called once per migration instance. ```javascript async function runMigration() { const migration = newMigration({ endpoint: "https://api-eu-central-1.hygraph.com/v2/clxxxxxx/master", authToken: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", }); migration.createModel({ apiId: "Post", apiIdPlural: "Posts", displayName: "Post", }); // Foreground: waits for completion const result = await migration.run(true); if (result.errors) { console.error("Migration failed:", result.errors); } else { console.log("Migration succeeded:", result.name); // Output: Migration succeeded: V1StGXR8_Z5jdHi6B-myT } } runMigration(); ``` -------------------------------- ### migration.createModel(args) / updateModel(args) / deleteModel(apiId) Source: https://context7.com/hygraph/management-sdk/llms.txt Manages content models by creating, updating, or deleting them. `createModel` and `updateModel` return a Model builder for chaining field operations. ```APIDOC ## migration.createModel(args) / updateModel(args) / deleteModel(apiId) ### Description Creates, updates, or deletes a content model. Returns a `Model` builder (on create/update) that you can chain field additions onto. `apiId` and `apiIdPlural` must start with an uppercase letter. ### Parameters #### createModel / updateModel - **args** (object) - Required - Arguments for model creation/update. Must include: - **apiId** (string) - Required - The API identifier for the model (starts with uppercase). - **apiIdPlural** (string) - Required - The plural API identifier for the model (starts with uppercase). - **displayName** (string) - Required - The display name of the model. - **description** (string) - Optional - A description for the model. #### deleteModel - **apiId** (string) - Required - The API identifier of the model to delete. ### Chained Methods (on `createModel` / `updateModel` return value) #### `addSimpleField(args)` - **args** (object) - Required - Arguments for adding a simple field. Must include: - **apiId** (string) - Required - The API identifier for the field. - **displayName** (string) - Required - The display name for the field. - **type** (FieldType enum) - Required - The data type of the field (e.g., `FieldType.String`, `FieldType.Float`). - **isRequired** (boolean) - Optional - Whether the field is required. ### Request Example ```js const migration = newMigration({ endpoint: "...", authToken: "..." }); // Create a model and immediately add fields const product = migration.createModel({ apiId: "Product", apiIdPlural: "Products", displayName: "Product", description: "A store product", }); product .addSimpleField({ apiId: "name", displayName: "Name", type: FieldType.String, isRequired: true }) .addSimpleField({ apiId: "price", displayName: "Price", type: FieldType.Float }) .addSimpleField({ apiId: "inStock", displayName: "In Stock", type: FieldType.Boolean }) .addSimpleField({ apiId: "publishedAt", displayName: "Published At",type: FieldType.DateTime }); // Update an existing model's display name migration.updateModel({ apiId: "Product", displayName: "Store Product" }); // Delete a model migration.deleteModel("OldModel"); await migration.run(true); ``` ``` -------------------------------- ### Create Model Source: https://github.com/hygraph/management-sdk/blob/main/README.md Creates a new model, which defines the structure of your schema. ```APIDOC ## Create Model ### Description A model can be created by passing in the required parameters. ### Method `migration.createModel(options)` ### Parameters - **apiId** (string) - The unique API identifier for the model (must start with an uppercase letter). - **apiIdPlural** (string) - The plural API identifier for the model (must start with an uppercase letter). - **displayName** (string) - The display name of the model. - **description** (string) - A description for the model. ### Usage ```js const modelName = migration.createModel({ apiId, // must start with upper case letter apiIdPlural, // must start with upper case letter displayName, description, }); ``` ``` -------------------------------- ### migration.createStage / updateStage / deleteStage Source: https://context7.com/hygraph/management-sdk/llms.txt Manages content stages, which control the publishing workflow for content entries. Supports creation, modification, and deletion of stages. ```APIDOC ## createStage / updateStage / deleteStage ### Description Creates, updates, or deletes a content stage (e.g., `Review`, `QA`). Stages control the publishing workflow for content entries. ### Methods - `migration.createStage(args)` - `migration.updateStage(args)` - `migration.deleteStage(apiId)` ### Parameters #### `args` (Object) - Required for create/update - `apiId` (String) - Required - Unique identifier for the stage. - `displayName` (String) - Required - User-friendly name for the stage. - `description` (String) - Optional - Description of the stage. - `color` (String) - Optional - Color associated with the stage (e.g., 'BLUE', 'GREEN'). - `isDefault` (Boolean) - Optional - Whether this is the default stage. - `allowQueries` (Boolean) - Optional - Whether queries are allowed on this stage. #### `apiId` (String) - Required for delete Unique identifier of the stage to delete. ``` -------------------------------- ### Dry Run a Migration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Performs a dry run of the migration to preview the changes that would be applied without actually making them. ```APIDOC ## Dry Run a Migration A migration can be dry run to preview what changes would be applied. ```js const changes = migration.dryRun(); console.log(changes); ``` ``` -------------------------------- ### migration.createGraphQLRemoteSource / createRESTRemoteSource Source: https://context7.com/hygraph/management-sdk/llms.txt Registers external GraphQL or REST APIs as remote sources, allowing their data to be surfaced via remote fields. ```APIDOC ## createGraphQLRemoteSource / createRESTRemoteSource ### Description Registers an external GraphQL or REST API as a remote source so its data can be surfaced via remote fields on your content models. ### Methods - `migration.createGraphQLRemoteSource(args)` - `migration.createRESTRemoteSource(args)` ### Parameters #### `args` (Object) - Required - `apiId` (String) - Required - Unique identifier for the remote source. - `displayName` (String) - Required - User-friendly name for the remote source. - `url` (String) - Required - The base URL of the remote API. - `headers` (Object) - Optional - HTTP headers to include in requests to the remote source. #### GraphQL Specific Parameters - `introspectionMethod` (RemoteSourceIntrospectionMethod) - Optional - Method for introspection (e.g., `RemoteSourceIntrospectionMethod.Get`). - `introspectionHeaders` (Object) - Optional - HTTP headers for introspection requests. #### REST Specific Parameters - `introspectionUrl` (String) - Optional - URL for OpenAPI/Swagger specification. ``` -------------------------------- ### Create Locale Source: https://github.com/hygraph/management-sdk/blob/main/README.md Creates a new locale within the Hygraph project with specified API ID, display name, and description. ```APIDOC ## Create a Locale To create a locale ```js migration.createLocale({ apiId, displayName, description, }); ``` ``` -------------------------------- ### Create a Hygraph Stage Source: https://github.com/hygraph/management-sdk/blob/main/README.md Define a new content stage within your Hygraph project. This includes setting its API ID, display name, description, and configuration for default status, queryability, and color. ```javascript migration.createStage({ apiId, displayName, description, isDefault, allowQueries, color, }); ``` -------------------------------- ### Create Simple Field with Form Renderer Source: https://github.com/hygraph/management-sdk/blob/main/README.md Configure a simple string field with a specific form renderer, such as MultiLine or Slug. Requires 'FieldType' and 'Renderer' imports. ```javascript const { FieldType, Renderer } = require("@hygraph/management-sdk"); model.addSimpleField({ apiId: '...', displayName: '...', type: FieldType.String, formRenderer: Renderer.MultiLine }); ``` -------------------------------- ### Create Asset Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Add a field to link assets. Set 'model' to 'Asset' to indicate an asset field. Optional 'reverseField' can be specified. ```javascript model.addRelationalField({ apiId, displayName, model: "Asset", // this is compulsory to indicate Asset field. // optional but can be specified to customize the details. reverseField: { apiId, displayName, }, }); ``` -------------------------------- ### Manage Content Stages - Hygraph SDK Source: https://context7.com/hygraph/management-sdk/llms.txt Create, update, or delete content stages to control publishing workflows. Stages can be configured with display names, colors, and query permissions. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); migration.createStage({ apiId: "QA", displayName: "QA Review", description: "Content staged for QA review", color: "BLUE", isDefault: false, allowQueries: true, }); migration.updateStage({ apiId: "QA", displayName: "Quality Assurance", color: "GREEN", }); migration.deleteStage("OldStage"); await migration.run(true); ``` -------------------------------- ### Preview Migration Changes with dryRun Source: https://context7.com/hygraph/management-sdk/llms.txt Generates an array of pending schema change operations without applying them to Hygraph. Useful for auditing or debugging before execution. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); migration.createModel({ apiId: "Author", apiIdPlural: "Authors", displayName: "Author" }); migration.createModel({ apiId: "Post", apiIdPlural: "Posts", displayName: "Post" }); const changes = migration.dryRun(); console.log(JSON.stringify(changes, null, 2)); // Output: // [ // { "createModel": { "apiId": "Author", "apiIdPlural": "Authors", "displayName": "Author" } }, // { "createModel": { "apiId": "Post", "apiIdPlural": "Posts", "displayName": "Post" } } // ] ``` -------------------------------- ### Create Simple Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Add a basic field to a model. Supports various types like String, Integer, etc. Requires 'FieldType' import. ```javascript const { FieldType } = require("@hygraph/management-sdk"); model.addSimpleField({ apiId: '...', displayName: '...', type: FieldType.String, }); ``` -------------------------------- ### Retrieve and Add Simple Fields to Model - Hygraph SDK Source: https://context7.com/hygraph/management-sdk/llms.txt Fetch an existing model using `migration.model(apiId)` to add simple fields without altering the model's schema. Use `addSimpleField` for this purpose. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); // Retrieve existing model — no schema change to the model itself const author = migration.model("Author"); author.addSimpleField({ apiId: "bio", displayName: "Biography", type: FieldType.String, formRenderer: Renderer.MultiLine, }); author.addSimpleField({ apiId: "twitterHandle", displayName: "Twitter Handle", type: FieldType.String, }); await migration.run(true); ``` -------------------------------- ### migration.createLocale / updateLocale / deleteLocale Source: https://context7.com/hygraph/management-sdk/llms.txt Manages locales for multi-language content publishing. Supports adding, modifying, and deleting locales within a Hygraph project. ```APIDOC ## createLocale / updateLocale / deleteLocale ### Description Adds, updates, or deletes a locale for multi-language content publishing within a Hygraph project. ### Methods - `migration.createLocale(args)` - `migration.updateLocale(args)` - `migration.deleteLocale(apiId)` ### Parameters #### `args` (Object) - Required for create/update - `apiId` (String) - Required - Unique identifier for the locale (e.g., 'en', 'de'). - `displayName` (String) - Required - User-friendly name for the locale (e.g., 'English', 'German'). - `description` (String) - Optional - Description of the locale. #### `apiId` (String) - Required for delete Unique identifier of the locale to delete. ``` -------------------------------- ### migration.dryRun() Source: https://context7.com/hygraph/management-sdk/llms.txt Returns an array of pending schema change objects without executing the migration. Useful for previewing changes. ```APIDOC ## migration.dryRun() ### Description Returns the array of change objects that would be submitted, without actually running the migration. Useful for debugging or auditing schema changes before applying them. ### Response #### Success Response (200) - **changes** (array) - An array of change objects representing the pending migration operations. ### Request Example ```js const migration = newMigration({ endpoint: "...", authToken: "..." }); migration.createModel({ apiId: "Author", apiIdPlural: "Authors", displayName: "Author" }); migration.createModel({ apiId: "Post", apiIdPlural: "Posts", displayName: "Post" }); const changes = migration.dryRun(); console.log(JSON.stringify(changes, null, 2)); ``` ``` -------------------------------- ### Create Enumeration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Creates a new enumeration with specified values. Values can be added individually or in batches. ```APIDOC ## Create Enumeration ### Description Creates an enumeration with values. ### Method `migration.createEnumeration(options)` ### Parameters - **apiId** (string) - The unique API identifier for the enumeration. - **displayName** (string) - The display name of the enumeration. - **description** (string) - A description for the enumeration. ### Usage ```js const colors = migration.createEnumeration({ apiId, displayName, description, }); // add values colors.addValue("Red"); colors.addValue("Green"); // or add multiple values at a time. colors.addValue("Blue", "Yellow"); ``` ``` -------------------------------- ### Manage Remote Sources (GraphQL & REST) - Hygraph SDK Source: https://context7.com/hygraph/management-sdk/llms.txt Register external GraphQL or REST APIs as remote sources to integrate their data into Hygraph via remote fields. Configure introspection and headers as needed. ```javascript const { newMigration, RemoteSourceIntrospectionMethod } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); // Register a GraphQL remote source migration.createGraphQLRemoteSource({ apiId: "SpacexAPI", displayName: "SpaceX API", url: "https://api.spacex.land/graphql", introspectionMethod: RemoteSourceIntrospectionMethod.Get, headers: { "X-App-Id": "hygraph-integration" }, introspectionHeaders: { "X-App-Id": "hygraph-integration" }, }); // Register a REST remote source migration.createRESTRemoteSource({ apiId: "InventoryAPI", displayName: "Inventory API", url: "https://inventory.example.com/api", headers: { Authorization: "Bearer " }, introspectionUrl: "https://inventory.example.com/api/openapi.json", }); await migration.run(true); ``` -------------------------------- ### migration.model Source: https://context7.com/hygraph/management-sdk/llms.txt Retrieves an existing model for performing field operations without directly modifying the model schema. ```APIDOC ## model(apiId) ### Description Fetches a reference to an already-existing model (without queuing an update to the model itself) so you can add, update, or delete fields on it in a migration. ### Method Signature `migration.model(apiId)` ### Parameters #### `apiId` (String) - Required Unique identifier of the model to retrieve. ``` -------------------------------- ### Create Relational Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Establish a relationship between two models. Supports relation types like OneToOne. Requires 'RelationType' import. ```javascript const { RelationType } = require("@hygraph/management-sdk"); model.addRelationalField({ apiId, displayName, relationType: RelationType.OneToOne, model, // the related model // optional but can be specified to customize the details. reverseField: { apiId, displayName, }, }); ``` -------------------------------- ### Create Asset Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Adds a field to a model for managing assets. ```APIDOC To create an asset field. ```js model.addRelationalField({ apiId, displayName, model: "Asset", // this is compulsory to indicate Asset field. // optional but can be specified to customize the details. reverseField: { apiId, displayName, }, }); ``` ``` -------------------------------- ### migration.createEnumeration / updateEnumeration / deleteEnumeration Source: https://context7.com/hygraph/management-sdk/llms.txt Manages enumerations, which are fixed sets of string values. Supports creation, modification (adding, renaming, removing values), and deletion. ```APIDOC ## createEnumeration / updateEnumeration / deleteEnumeration ### Description Creates, updates, or deletes an enumeration (a fixed set of string values). On creation, values are added via `addValue()`. On update, you can add, rename, or remove individual values. ### Methods - `migration.createEnumeration(args)` - `migration.updateEnumeration(args)` - `migration.deleteEnumeration(apiId)` ### Parameters #### `args` (Object) - Required for create/update - `apiId` (String) - Required - Unique identifier for the enumeration. - `displayName` (String) - Required - User-friendly name for the enumeration. - `description` (String) - Optional - Description of the enumeration. #### `apiId` (String) - Required for delete Unique identifier of the enumeration to delete. ### Value Management (for create/update) - `addValue(name, ...)`: Adds one or more new values to the enumeration. - `updateValue(oldName, newName)`: Renames an existing value. - `deleteValue(name)`: Removes a value from the enumeration. ``` -------------------------------- ### Create Simple Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Adds a simple field to a model, such as a string, integer, or boolean. ```APIDOC #### Create a Field To create a simple field. ```js const { FieldType } = require("@hygraph/management-sdk"); model.addSimpleField({ apiId: '...', displayName: '...', type: FieldType.String, }); ``` String fields have several [form renderers](/src/renderer.ts#L4-L10), including single line, multiline, markdown, and slug. You can set the form renderer as follows: ```js const { FieldType, Renderer } = require("@hygraph/management-sdk"); model.addSimpleField({ apiId: '...', displayName: '...', type: FieldType.String, formRenderer: Renderer.MultiLine }); ``` ``` -------------------------------- ### Create Enumerable Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Add a field that uses a predefined enumeration. Requires the 'enumerationApiId' of an existing enumeration. ```javascript model.addEnumerableField({ apiId, displayName, enumerationApiId, // previously created enumeration. }); ``` -------------------------------- ### Update Stage Source: https://github.com/hygraph/management-sdk/blob/main/README.md Updates an existing content stage identified by its API ID. Properties to be updated can be provided. ```APIDOC ## Update a Stage To update a stage ```js migration.updateStage({ apiId, ... // properties to update }); ``` ``` -------------------------------- ### Update Model Source: https://github.com/hygraph/management-sdk/blob/main/README.md Updates an existing model with new properties. ```APIDOC ## Update Model ### Description To update a model. ### Method `migration.updateModel(options)` ### Parameters - **apiId** (string) - The unique API identifier of the model to update (required). - **properties to update** - Any properties of the model to be updated. ### Usage ```js migration.updateModel({ apiId, // required ... // properties to update }); ``` ``` -------------------------------- ### Create a Hygraph Locale Source: https://github.com/hygraph/management-sdk/blob/main/README.md Use this method to add a new locale to your Hygraph project, specifying its API ID, display name, and an optional description. ```javascript migration.createLocale({ apiId, displayName, description, }); ``` -------------------------------- ### Manage Simple Fields Source: https://context7.com/hygraph/management-sdk/llms.txt Adds or updates a scalar field (String, Int, Float, Boolean, DateTime, etc.) on a model. Supports validations for Int, Float, and String types. ```APIDOC ## `model.addSimpleField(field)` / `updateSimpleField` / `deleteField` — Manage simple fields Adds or updates a scalar field (String, Int, Float, Boolean, DateTime, etc.) on a model. String fields can specify a `formRenderer`. Field validations (range, character count, regex) are supported for Int, Float, and String types. ### Example Usage: ```js const { newMigration, FieldType, Renderer, VisibilityTypes } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); const article = migration.model("Article"); // retrieve existing model // Add a markdown body field article.addSimpleField({ apiId: "body", displayName: "Body", type: FieldType.String, formRenderer: Renderer.Markdown, isRequired: true, }); // Add a string field with validations article.addSimpleField({ apiId: "slug", displayName: "Slug", type: FieldType.String, formRenderer: Renderer.Slug, validations: { characters: { min: 3, max: 255 }, matches: { regex: "^[a-z0-9]+(?:-[a-z0-9]+)*$" }, }, }); // Add an Int field with range validation article.addSimpleField({ apiId: "readingTime", displayName: "Reading Time (min)", type: FieldType.Int, validations: { range: { min: 1, max: 120 } }, }); // Update an existing field article.updateSimpleField({ apiId: "slug", displayName: "URL Slug" }); // Delete a field article.deleteField("oldField"); await migration.run(true); ``` ``` -------------------------------- ### Create Union Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Create a field that can relate to multiple models. Requires 'RelationType' import and a list of related models. ```javascript const { RelationType } = require("@hygraph/management-sdk"); model.addUnionField({ apiId, displayName, relationType: RelationType.OneToOne, models, // list of related models // optional but can be specified to customize the details. reverseField: { apiId, displayName, }, }); ``` -------------------------------- ### Create Enumerable Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Adds an enumerable field to a model, linking it to a previously created enumeration. ```APIDOC To create an enumerable field. ```js model.addEnumerableField({ apiId, displayName, enumerationApiId, // previously created enumeration. }); ``` ``` -------------------------------- ### Add and Manage Enumerable Fields in Hygraph Models Source: https://context7.com/hygraph/management-sdk/llms.txt Use `addEnumerableField` to create fields constrained to a predefined enumeration. The `enumerationApiId` must reference an existing enumeration. First, create the enumeration using `migration.createEnumeration` and add values using `addValue`. Then, add the field to the model. Changes are applied with `migration.run(true)`. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); // First ensure the enumeration exists const statusEnum = migration.createEnumeration({ apiId: "PostStatus", displayName: "Post Status", }); statusEnum.addValue("Draft", "Published", "Archived"); // Then add the enum field to a model const post = migration.model("Post"); post.addEnumerableField({ apiId: "status", displayName: "Status", enumerationApiId: "PostStatus", isRequired: true, }); await migration.run(true); ``` -------------------------------- ### Manage Relational Fields Source: https://context7.com/hygraph/management-sdk/llms.txt Adds a relation between two models. Supports `OneToOne`, `OneToMany`, `ManyToOne`, and `ManyToMany` relation types via the `RelationType` enum. Use `model: "Asset"` to create an asset relation field. ```APIDOC ## `model.addRelationalField(field)` / `updateRelationalField` — Manage relational fields Adds a relation between two models. Supports `OneToOne`, `OneToMany`, `ManyToOne`, and `ManyToMany` relation types via the `RelationType` enum. Use `model: "Asset"` to create an asset relation field. ### Example Usage: ```js const { newMigration, RelationType } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); const post = migration.model("Post"); // One-to-many: one Author has many Posts post.addRelationalField({ apiId: "author", displayName: "Author", relationType: RelationType.ManyToOne, model: "Author", reverseField: { apiId: "posts", displayName: "Posts", }, }); // Asset field (cover image) post.addRelationalField({ apiId: "coverImage", displayName: "Cover Image", model: "Asset", isRequired: false, }); // Many-to-many: Posts <-> Tags post.addRelationalField({ apiId: "tags", displayName: "Tags", relationType: RelationType.ManyToMany, model: "Tag", reverseField: { apiId: "posts", displayName: "Posts", }, }); await migration.run(true); ``` ``` -------------------------------- ### model.addRemoteField / updateRemoteField Source: https://context7.com/hygraph/management-sdk/llms.txt Manages fields that fetch data from a remote source (GraphQL or REST). The field resolves data at query time from the external API. ```APIDOC ## addRemoteField / updateRemoteField ### Description Adds or updates a field that fetches data from a remote source (GraphQL or REST) configured on the project. The field resolves data at query time from the external API. ### Method Signature `model.addRemoteField(field)` or `model.updateRemoteField(field)` ### Parameters #### `field` (Object) - Required - `apiId` (String) - Required - Unique identifier for the remote field. - `displayName` (String) - Required - User-friendly name for the remote field. - `remoteSourceApiId` (String) - Required - The `apiId` of the previously created remote source. - `remoteTypeApiId` (String) - Required - The `apiId` of the remote type to fetch. - `apiMethod` (RemoteFieldApiMethod) - Required - The HTTP method to use for fetching data (e.g., `RemoteFieldApiMethod.Get`). - `type` (RemoteFieldType) - Required - The data type of the remote field (e.g., `RemoteFieldType.Object`). - `inputArgs` (Array) - Optional - Arguments required by the remote API. - `name` (String) - Required - Name of the input argument. - `isList` (Boolean) - Required - Whether the argument is a list. - `isRequired` (Boolean) - Required - Whether the argument is required. - `type` (String) - Required - Data type of the argument. - `forwardClientHeaders` (Boolean) - Optional - Whether to forward client headers to the remote source. ``` -------------------------------- ### Manage Locales - Hygraph SDK Source: https://context7.com/hygraph/management-sdk/llms.txt Add or modify locales for multi-language content publishing. This allows you to manage different language versions of your content within Hygraph. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); migration.createLocale({ apiId: "de", displayName: "German", description: "German (Germany)", }); migration.updateLocale({ apiId: "de", displayName: "Deutsch", }); migration.deleteLocale("fr"); await migration.run(true); ``` -------------------------------- ### Add, Update, and Delete Simple Fields in Hygraph Models Source: https://context7.com/hygraph/management-sdk/llms.txt Use `addSimpleField` to add scalar fields like String, Int, Float, Boolean, or DateTime. String fields support `formRenderer` and validations for range, character count, and regex. `updateSimpleField` modifies existing fields, and `deleteField` removes them. Ensure to call `migration.run(true)` to apply changes. ```javascript const { newMigration, FieldType, Renderer, VisibilityTypes } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); const article = migration.model("Article"); // retrieve existing model // Add a markdown body field article.addSimpleField({ apiId: "body", displayName: "Body", type: FieldType.String, formRenderer: Renderer.Markdown, isRequired: true, }); // Add a string field with validations article.addSimpleField({ apiId: "slug", displayName: "Slug", type: FieldType.String, formRenderer: Renderer.Slug, validations: { characters: { min: 3, max: 255 }, matches: { regex: "^[a-z0-9]+(?:-[a-z0-9]+)*$" }, }, }); // Add an Int field with range validation article.addSimpleField({ apiId: "readingTime", displayName: "Reading Time (min)", type: FieldType.Int, validations: { range: { min: 1, max: 120 } }, }); // Update an existing field article.updateSimpleField({ apiId: "slug", displayName: "URL Slug" }); // Delete a field article.deleteField("oldField"); await migration.run(true); ``` -------------------------------- ### Update Locale Source: https://github.com/hygraph/management-sdk/blob/main/README.md Updates an existing locale identified by its API ID. Any specified properties will be updated. ```APIDOC ## Update a Locale To update a locale ```js migration.updateLocale({ apiId, ... // properties to update }); ``` ``` -------------------------------- ### Update Enumeration and its Values Source: https://github.com/hygraph/management-sdk/blob/main/README.md Modify an existing enumeration by adding new values, updating existing ones, or deleting them. ```javascript const colors = migration.updateEnumeration({ apiId, ... // properties to update. }); colors.addValue("Black"); // add a new value colors.updateValue("Red", "Dark Red"); // update existing value colors.deleteValue("Blue"); // delete value ``` -------------------------------- ### Manage Enumerations - Hygraph SDK Source: https://context7.com/hygraph/management-sdk/llms.txt Create, update, or delete enumerations (fixed sets of string values) for your Hygraph models. Use addValue(), updateValue(), and deleteValue() for modifications. ```javascript const migration = newMigration({ endpoint: "...", authToken: "..." }); // Create const colors = migration.createEnumeration({ apiId: "Color", displayName: "Color", description: "Available product colors", }); colors.addValue("Red", "Green", "Blue"); // Update: add Black, rename Red to DarkRed, remove Blue const colorsUpdate = migration.updateEnumeration({ apiId: "Color" }); colorsUpdate.addValue("Black"); colorsUpdate.updateValue("Red", "DarkRed"); colorsUpdate.deleteValue("Blue"); // Delete migration.deleteEnumeration("OldEnum"); await migration.run(true); ``` -------------------------------- ### Update a Hygraph Stage Source: https://github.com/hygraph/management-sdk/blob/main/README.md Modify an existing content stage. Provide the `apiId` of the stage to update and specify the properties you want to change. ```javascript migration.updateStage({ apiId, ... // properties to update }); ``` -------------------------------- ### Update Model Source: https://github.com/hygraph/management-sdk/blob/main/README.md Modify an existing model's properties. The 'apiId' is required to identify the model. ```javascript migration.updateModel({ apiId, // required ... // properties to update }); ``` -------------------------------- ### Update Simple Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Modify properties of an existing simple field. Requires the field's 'apiId'. ```javascript model.updateSimpleField({ apiId, ... // properties to update }) ``` -------------------------------- ### Manage Union Fields Source: https://context7.com/hygraph/management-sdk/llms.txt Adds a union (polymorphic) field that can relate to multiple model types at once. The `models` array lists all the model `apiId`s the union can reference. ```APIDOC ## `model.addUnionField(field)` / `updateUnionField` — Manage union fields Adds a union (polymorphic) field that can relate to multiple model types at once. The `models` array lists all the model `apiId`s the union can reference. ### Example Usage: ```js const { newMigration, RelationType } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); const page = migration.model("Page"); // A page's content blocks can be TextBlock, ImageBlock, or VideoBlock page.addUnionField({ apiId: "contentBlocks", displayName: "Content Blocks", relationType: RelationType.OneToMany, models: ["TextBlock", "ImageBlock", "VideoBlock"], reverseField: { apiId: "page", displayName: "Page", }, }); // Update union to add a new model page.updateUnionField({ apiId: "contentBlocks", models: ["TextBlock", "ImageBlock", "VideoBlock", "QuoteBlock"], }); await migration.run(true); ``` ``` -------------------------------- ### Update Enumeration Source: https://github.com/hygraph/management-sdk/blob/main/README.md Updates an existing enumeration, allowing for adding, updating, or deleting its values. ```APIDOC ## Update Enumeration ### Description Updates an enumeration and its values. ### Method `migration.updateEnumeration(options)` ### Parameters - **apiId** (string) - The unique API identifier for the enumeration to update. - **properties to update** - Any properties of the enumeration to be updated. ### Usage ```js const colors = migration.updateEnumeration({ apiId, ... // properties to update. }); colors.addValue("Black"); // add a new value colors.updateValue("Red", "Dark Red"); // update existing value colors.deleteValue("Blue"); // delete value ``` ``` -------------------------------- ### Update Simple Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Updates the properties of a simple field within a model. ```APIDOC Updating simple field ```js model.updateSimpleField({ apiId, ... // properties to update }) ``` ``` -------------------------------- ### Add Remote Field to Model - Hygraph SDK Source: https://context7.com/hygraph/management-sdk/llms.txt Use this to add a field to a model that fetches data from a remote GraphQL or REST API. Ensure the remote source is configured on the project. ```javascript const { newMigration, RemoteFieldType, RemoteFieldApiMethod } = require("@hygraph/management-sdk"); const migration = newMigration({ endpoint: "...", authToken: "..." }); const product = migration.model("Product"); product.addRemoteField({ apiId: "inventory", displayName: "Inventory", remoteSourceApiId: "InventoryAPI", // previously created REST remote source remoteTypeApiId: "InventoryResponse", apiMethod: RemoteFieldApiMethod.Get, type: RemoteFieldType.Object, inputArgs: [ { name: "sku", isList: false, isRequired: true, type: "String" }, ], forwardClientHeaders: true, }); await migration.run(true); ``` -------------------------------- ### Create Union Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Adds a union field to a model, allowing it to relate to multiple other models. ```APIDOC To create a union field. ```js const { RelationType } = require("@hygraph/management-sdk"); model.addUnionField({ apiId, displayName, relationType: RelationType.OneToOne, models, // list of related models // optional but can be specified to customize the details. reverseField: { apiId, displayName, }, }); ``` ``` -------------------------------- ### Manage Enumerable Fields Source: https://context7.com/hygraph/management-sdk/llms.txt Adds a field whose values are constrained to a previously defined enumeration. The `enumerationApiId` must refer to an existing enumeration in the schema. ```APIDOC ## `model.addEnumerableField(field)` / `updateEnumerableField` — Manage enumerable fields Adds a field whose values are constrained to a previously defined enumeration. The `enumerationApiId` must refer to an existing enumeration in the schema. ### Example Usage: ```js const migration = newMigration({ endpoint: "...", authToken: "..." }); // First ensure the enumeration exists const statusEnum = migration.createEnumeration({ apiId: "PostStatus", displayName: "Post Status", }); statusEnum.addValue("Draft", "Published", "Archived"); // Then add the enum field to a model const post = migration.model("Post"); post.addEnumerableField({ apiId: "status", displayName: "Status", enumerationApiId: "PostStatus", isRequired: true, }); await migration.run(true); ``` ``` -------------------------------- ### Create Relational Field Source: https://github.com/hygraph/management-sdk/blob/main/README.md Adds a relational field to a model, defining relationships between models (e.g., one-to-one, one-to-many). ```APIDOC To create a relational field. ```js const { RelationType } = require("@hygraph/management-sdk"); model.addRelationalField({ apiId, displayName, relationType: RelationType.OneToOne, model, // the related model // optional but can be specified to customize the details. reverseField: { apiId, displayName, }, }); ``` ```