graphgateway

package
v1.0.0-alpha.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 22 Imported by: 0

README

graph-gateway

HTTP gateway component for external access to the knowledge graph via GraphQL and MCP protocols.

Overview

The graph-gateway component provides HTTP endpoints for querying and mutating the knowledge graph. It serves as the external access layer, translating HTTP requests into KV reads (via QueryManager) and NATS mutations.

Architecture

                                   ┌─────────────────────┐
HTTP /graphql ──────────────────►  │                     │
                                   │   graph-gateway     │ ──► NATS graph.mutation.*
HTTP /mcp ──────────────────────►  │                     │
                                   │   (QueryManager)    │ ──► KV reads (direct)
HTTP / (playground) ────────────►  │                     │
                                   └─────────────────────┘

Features

  • GraphQL API: Full query and mutation support for graph operations
  • MCP Protocol: Model Context Protocol for LLM tool integration
  • GraphQL Playground: Interactive development IDE
  • Read-through KV: Direct KV access for queries (no NATS overhead)
  • Mutation Forwarding: Mutations sent via NATS to graph-ingest

Configuration

{
  "name": "graph-gateway",
  "type": "gateway",
  "config": {
    "graphql_path": "/graphql",
    "mcp_path": "/mcp",
    "bind_address": "localhost:8080",
    "enable_playground": true,
    "ports": {
      "inputs": [
        {"name": "http", "type": "http", "subject": "/graphql"}
      ],
      "outputs": [
        {"name": "mutations", "type": "nats-request", "subject": "graph.mutation.*"}
      ]
    }
  }
}
Configuration Options
Option Type Default Description
graphql_path string /graphql GraphQL endpoint path
mcp_path string /mcp MCP endpoint path
bind_address string localhost:8080 HTTP server bind address
enable_playground bool false Enable GraphQL playground UI

HTTP Endpoints

GraphQL (/graphql)

Standard GraphQL endpoint supporting:

Queries:

  • entity(id: ID!): Fetch single entity
  • entities(filter: EntityFilter): Search entities
  • triples(subject: ID, predicate: String, object: ID): Query triples
  • traverse(start: ID!, depth: Int!): Graph traversal
  • communities(algorithm: String): Community detection results

Mutations:

  • createEntity(input: EntityInput!): Create new entity
  • updateEntity(id: ID!, input: EntityInput!): Update entity
  • deleteEntity(id: ID!): Delete entity
  • createTriple(input: TripleInput!): Create relationship
  • deleteTriple(id: ID!): Delete relationship
MCP (/mcp)

Model Context Protocol endpoint for LLM integration:

Tools:

  • graph_query: Execute graph queries
  • entity_lookup: Find entities by alias or ID
  • relationship_find: Discover relationships
  • context_build: Build context from graph neighborhood
Playground (/)

When enabled, serves an interactive GraphQL IDE for:

  • Query composition and testing
  • Schema exploration
  • Response visualization

KV Bucket Access

The gateway reads from multiple KV buckets via QueryManager:

Bucket Purpose
ENTITY_STATES Entity data and properties
OUTGOING_INDEX Forward relationship traversal
INCOMING_INDEX Backward relationship traversal
ALIAS_INDEX Entity lookup by alias
PREDICATE_INDEX Predicate-based queries
EMBEDDINGS_CACHE Vector similarity (semantic tier)
COMMUNITY_INDEX Clustering results (semantic tier)
SPATIAL_INDEX Geospatial queries (if enabled)
TEMPORAL_INDEX Time-based queries (if enabled)
STRUCTURAL_INDEX Graph analytics (if enabled)

Integration

With graph-ingest

Mutations received by the gateway are forwarded via NATS:

  • graph.mutation.entity.create
  • graph.mutation.entity.update
  • graph.mutation.entity.delete
  • graph.mutation.triple.add
  • graph.mutation.triple.delete
With QueryManager

The gateway uses QueryManager for complex read operations:

  • Multi-hop traversals
  • Filtered entity searches
  • Aggregation queries

Security Considerations

Production deployments should:

  1. Disable playground (enable_playground: false)
  2. Deploy behind authentication proxy
  3. Implement rate limiting
  4. Use TLS termination at load balancer

Deployment

All Tiers

The gateway is required in all deployment tiers:

{
  "components": [
    {"type": "processor", "name": "graph-ingest"},
    {"type": "processor", "name": "graph-index"},
    {"type": "gateway", "name": "graph-gateway"}
  ]
}
High Availability

For production, deploy multiple gateway instances behind a load balancer. Each instance maintains its own QueryManager with KV connections.

Documentation

Overview

Package graphgateway provides the graph-gateway component for exposing graph operations via HTTP.

Package graphgateway provides the graph-gateway component for exposing graph operations via HTTP protocols including GraphQL and MCP.

Overview

The graph-gateway component serves as the external access layer for the knowledge graph. It provides HTTP endpoints for querying entities, triples, and graph analytics, as well as submitting mutations via NATS.

Component Interface

This component implements the semstreams component framework:

  • component.Discoverable (6 methods): Meta, InputPorts, OutputPorts, ConfigSchema, Health, DataFlow
  • component.LifecycleComponent (3 methods): Initialize, Start, Stop
  • gateway.Gateway (1 method): RegisterHTTPHandlers

Communication Patterns

Inputs:

  • HTTP requests on /graphql: GraphQL queries and mutations
  • HTTP requests on /mcp: Model Context Protocol operations

Outputs:

  • NATS requests to graph.mutation.*: Mutations forwarded to graph-ingest

Internal Reads (via QueryManager):

  • ENTITY_STATES: Entity data
  • OUTGOING_INDEX, INCOMING_INDEX: Graph traversal
  • ALIAS_INDEX, PREDICATE_INDEX: Lookups
  • EMBEDDINGS_CACHE: Vector similarity (semantic tier)
  • COMMUNITY_INDEX: Clustering results (semantic tier)
  • ANOMALY_INDEX: Structural anomalies for inference endpoints

HTTP Endpoints

GraphQL (/graphql):

  • Query entities, triples, and relationships
  • Perform graph traversals and analytics
  • Submit mutations (forwarded to graph-ingest via NATS)

MCP (/mcp):

  • Model Context Protocol for LLM tool integration
  • Provides structured graph operations for AI agents

Inference (/inference/*):

  • List pending anomalies for human review
  • Get anomaly details and submit review decisions
  • View inference statistics

Playground (/ when enabled):

  • Interactive GraphQL IDE for development

Configuration

Key configuration options:

  • graphql_path: GraphQL endpoint path (default: /graphql)
  • mcp_path: MCP endpoint path (default: /mcp)
  • bind_address: HTTP server address (default: localhost:8080)
  • enable_playground: Enable GraphQL playground (default: false)

Tiered Deployment

The graph-gateway component is typically required in all tiers as the external access point. In production, it should be deployed behind a load balancer with appropriate authentication.

Usage

// Register the component
registry := component.NewRegistry()
graphgateway.Register(registry)

// Create via factory
comp, err := graphgateway.CreateGraphGateway(configJSON, deps)
if err != nil {
    log.Fatal(err)
}

// Register HTTP handlers
mux := http.NewServeMux()
comp.(gateway.Gateway).RegisterHTTPHandlers("/api", mux)

// Lifecycle management
comp.Initialize()
comp.Start(ctx)
defer comp.Stop(5 * time.Second)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateGraphGateway

func CreateGraphGateway(rawConfig json.RawMessage, deps component.Dependencies) (component.Discoverable, error)

CreateGraphGateway is the factory function for creating graph-gateway components

func Register

func Register(registry *component.Registry) error

Register registers the graph-gateway factory with the component registry

Types

type Component

type Component struct {
	// contains filtered or unexported fields
}

Component implements the graph-gateway gateway

func (*Component) ConfigSchema

func (c *Component) ConfigSchema() component.ConfigSchema

ConfigSchema returns the configuration schema

func (*Component) DataFlow

func (c *Component) DataFlow() component.FlowMetrics

DataFlow returns current data flow metrics

func (*Component) Health

func (c *Component) Health() component.HealthStatus

Health returns current health status

func (*Component) Initialize

func (c *Component) Initialize() error

Initialize validates configuration and sets up ports (no I/O)

func (*Component) InputPorts

func (c *Component) InputPorts() []component.Port

InputPorts returns input port definitions. Reads directly from config so ports are available before Initialize().

func (*Component) Meta

func (c *Component) Meta() component.Metadata

Meta returns component metadata

func (*Component) OpenAPISpec

func (c *Component) OpenAPISpec() *service.OpenAPISpec

OpenAPISpec implements gateway.OpenAPIProvider interface.

func (*Component) OutputPorts

func (c *Component) OutputPorts() []component.Port

OutputPorts returns output port definitions. Reads directly from config so ports are available before Initialize().

func (*Component) RegisterHTTPHandlers

func (c *Component) RegisterHTTPHandlers(prefix string, mux *http.ServeMux)

RegisterHTTPHandlers registers HTTP handlers with the provided mux

func (*Component) Start

func (c *Component) Start(ctx context.Context) error

Start begins processing (must be initialized first)

func (*Component) Stop

func (c *Component) Stop(timeout time.Duration) error

Stop gracefully shuts down the component

type Config

type Config struct {
	Ports                     *component.PortConfig `json:"ports" schema:"type:ports,description:Port configuration,category:basic"`
	GraphQLPath               string                `json:"graphql_path" schema:"type:string,description:GraphQL endpoint path,category:basic"`
	MCPPath                   string                `json:"mcp_path" schema:"type:string,description:MCP endpoint path,category:basic"`
	BindAddress               string                `json:"bind_address" schema:"type:string,description:HTTP server bind address,category:basic"`
	EnablePlayground          bool                  `json:"enable_playground" schema:"type:bool,description:Enable GraphQL playground,category:basic"`
	EnableInferenceAPI        bool                  `json:"enable_inference_api" schema:"type:bool,description:Enable inference API for anomaly review,category:basic"`
	QueryTimeout              time.Duration         `json:"query_timeout" schema:"type:duration,description:Query timeout duration,category:basic"`
	DomainExamplesPath        string                `` /* 127-byte string literal not displayed */
	EnableEmbeddingClassifier bool                  `` /* 141-byte string literal not displayed */
}

Config holds configuration for graph-gateway component

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a valid default configuration

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults sets default values for configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate implements component.Validatable interface

type GraphQLRequest

type GraphQLRequest struct {
	Query     string         `json:"query"`
	Variables map[string]any `json:"variables,omitempty"`
}

GraphQLRequest represents the request body for GraphQL queries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL