ID

Unique identifier scalar type

Audience: Programmer

The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human-readable.

Format

  • Serialized as String

  • Not intended for human consumption

  • Must be unique within its type

  • Often UUIDs or database primary keys

Usage

type InventoryItem {
  id: ID!
  sku: String!
}

query {
  inventoryItem(id: "550e8400-e29b-41d4-a716-446655440000") {
    sku
  }
}

Best Practices

  1. Always treat IDs as opaque strings

  2. Never parse or manipulate ID values

  3. Use for caching and refetching

  4. Consider using UUIDs for distributed systems

See Also

Last updated

Was this helpful?