• Sanitizes a string to be a valid GraphQL name component, preserving original capitalization. GraphQL names must match the pattern [_A-Za-z][_0-9A-Za-z]* and cannot start with double underscore

    Parameters

    • input: string

      The string to sanitize

    Returns string

    A valid GraphQL name component with special characters removed

    Example

    // Input: Schema name with special characters
    sanitizeGraphQLName("my-schema")
    // Output: "myschema"

    Example

    // Input: Name starting with double underscore (reserved)
    sanitizeGraphQLName("__mj_User")
    // Output: "mjUser"
    // (Removes __ prefix and underscores)

    Example

    // Input: Name starting with a digit
    sanitizeGraphQLName("123Orders")
    // Output: "_123Orders"
    // (Prepends underscore since GraphQL names can't start with digits)

    Example

    // Input: Preserves capitalization
    sanitizeGraphQLName("MyTable_Name")
    // Output: "MyTableName"
    // (Removes underscores but preserves case)

    Example

    // Input: Empty or invalid input
    sanitizeGraphQLName("")
    // Output: ""

    sanitizeGraphQLName("!!!###")
    // Output: "_"
    // (All chars removed, so prepends underscore)