graphql

package
v0.4.9 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package graphql provides a GraphQL API adapter for CoreMCP. It can discover the schema via introspection and expose queries/mutations as MCP tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(dsn string) (core.Source, error)

New creates a new GraphQL API adapter. The dsn format is: graphql://endpoint?apiKey=xxx&timeout=30 Headers can be provided as: header_X-Custom=value

Types

type Field

type Field struct {
	Name              string       `json:"name"`
	Description       string       `json:"description"`
	Args              []InputValue `json:"args"`
	Type              *TypeDesc    `json:"type"`
	IsDeprecated      bool         `json:"isDeprecated"`
	DeprecationReason string       `json:"deprecationReason"`
}

Field represents a field in a GraphQL type.

type FullType

type FullType struct {
	Kind        string       `json:"kind"`
	Name        string       `json:"name"`
	Description string       `json:"description"`
	Fields      []Field      `json:"fields"`
	InputFields []InputValue `json:"inputFields"`
}

FullType represents a complete GraphQL type definition.

type GraphQLAdapter

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

GraphQLAdapter provides access to GraphQL APIs with schema introspection.

func (*GraphQLAdapter) Close

func (g *GraphQLAdapter) Close(_ context.Context) error

func (*GraphQLAdapter) Connect

func (g *GraphQLAdapter) Connect(ctx context.Context) error

func (*GraphQLAdapter) ExecuteProcedure

func (g *GraphQLAdapter) ExecuteProcedure(ctx context.Context, name string, params map[string]string) (*core.QueryResult, error)

ExecuteProcedure executes a GraphQL operation by name. Variable types are resolved from the introspected schema; falls back to String.

func (*GraphQLAdapter) ExecuteQuery

func (g *GraphQLAdapter) ExecuteQuery(ctx context.Context, query string, args ...any) (*core.QueryResult, error)

ExecuteQuery runs a raw GraphQL query string.

func (*GraphQLAdapter) GetOperations

func (g *GraphQLAdapter) GetOperations() []GraphQLOperation

GetOperations returns all available queries and mutations.

func (*GraphQLAdapter) GetProcedures

func (g *GraphQLAdapter) GetProcedures(_ context.Context) ([]core.StoredProcedure, error)

GetProcedures returns available queries and mutations as procedures.

func (*GraphQLAdapter) GetSchema

func (g *GraphQLAdapter) GetSchema(_ context.Context) ([]core.TableSchema, error)

GetSchema returns the discovered GraphQL types as "tables" for schema context.

func (*GraphQLAdapter) GetSchemaDescription

func (g *GraphQLAdapter) GetSchemaDescription() string

GetSchemaDescription returns a human-readable description of the schema.

func (*GraphQLAdapter) GetViews

func (g *GraphQLAdapter) GetViews(_ context.Context) ([]core.ViewSchema, error)

func (*GraphQLAdapter) Name

func (g *GraphQLAdapter) Name() string

type GraphQLOperation

type GraphQLOperation struct {
	Name        string
	Type        string // query, mutation, subscription
	Description string
	Fields      []Field
	ReturnType  string
}

GraphQLOperation represents a discovered operation that can be exposed as an MCP tool.

type GraphQLSchema

type GraphQLSchema struct {
	Data struct {
		Schema *IntrospectionSchema `json:"__schema"`
	} `json:"data"`
}

GraphQLSchema represents the introspected GraphQL schema.

type InputValue

type InputValue struct {
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	Type         *TypeDesc `json:"type"`
	DefaultValue *string   `json:"defaultValue"`
}

InputValue represents an input value (argument or input field).

type IntrospectionSchema

type IntrospectionSchema struct {
	QueryType        *TypeRef                 `json:"queryType"`
	MutationType     *TypeRef                 `json:"mutationType"`
	SubscriptionType *TypeRef                 `json:"subscriptionType"`
	Types            []FullType               `json:"types"`
	Directives       []map[string]interface{} `json:"directives"`
}

IntrospectionSchema represents the full GraphQL schema.

type TypeDesc

type TypeDesc struct {
	Kind   string    `json:"kind"`
	Name   string    `json:"name"`
	OfType *TypeDesc `json:"ofType"`
}

TypeDesc describes a GraphQL type (possibly wrapped in NON_NULL or LIST).

type TypeRef

type TypeRef struct {
	Name string `json:"name"`
	Kind string `json:"kind"`
}

TypeRef is a reference to a GraphQL type.

Jump to

Keyboard shortcuts

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