tentacle-graphql

tentacle-graphql

GraphQL API with real-time subscriptions for the Tentacle platform.

Tech Stack

  • graphql-yoga
  • Pothos schema builder
  • NATS for data source

Port

Default: 4000

Key Features

  • Real-time variable subscriptions: Subscribes to {moduleId}.data.> on NATS, scoped per-module. Batches updates every 2.5s to avoid SSE overhead
  • Service topology: Reads service_heartbeats KV bucket to return live service list
  • Log streaming: Subscribes to service.logs.{serviceType}.> and forwards via GraphQL subscription
  • NATS traffic inspector: Real-time view of NATS message traffic
  • Browse tags: Async browse mutation with progress subscription (for EtherNet/IP and OPC UA)
  • Network management: Forwards network state and configuration commands
  • nftables NAT management: Forwards NAT config state and apply commands

GraphQL Subscriptions

# Batched variable updates scoped to a module (recommended)
# Batches every 2.5s to reduce SSE overhead for high-tag-count scanners
subscription {
  variableBatchUpdates(moduleId: "ethernetip") {
    moduleId
    variableId
    value
    datatype
    timestamp
  }
}

# All variable updates from all modules (unbatched, legacy)
subscription {
  variableUpdates(moduleId: "ethernetip") {
    moduleId
    variableId
    value
    datatype
    timestamp
  }
}

# Real-time service logs
subscription {
  serviceLogs(serviceType: "ethernetip") {
    timestamp
    level
    message
    moduleId
    logger
  }
}

# Real-time NATS message traffic (optional filter)
subscription {
  natsTraffic(filter: "ethernetip.>") {
    subject
    payload
    timestamp
  }
}

# Live network interface state
subscription {
  networkState {
    interfaces { name operstate addresses { address } }
  }
}

# Live nftables NAT config
subscription {
  nftablesConfig {
    natRules { id natAddr deviceAddr deviceName enabled }
  }
}

# Browse progress for async browse operations
subscription {
  browseProgress(browseId: "...") {
    phase
    totalTags
    completedTags
    message
  }
}

Key Files

FilePurpose
main.tsEntry point, NATS + HTTP server setup
server.tsgraphql-yoga server configuration
schema/schema.tsSchema assembly
schema/types.tsGraphQL type definitions (Pothos)
schema/queries.tsQueries (variables, services, etc.)
schema/mutations.tsMutations (browse, command, apply, etc.)
schema/subscriptions.tsReal-time subscriptions
nats/client.tsNATS connection, pub/sub, request helpers
nats/watcher.tsVariable update async iterable with filtering
modules/logs.tsLog streaming, ring buffer (200 entries per service)
modules/nats-traffic.tsNATS traffic inspection
modules/network.tsNetwork state forwarding
modules/nftables.tsnftables state/config forwarding