graphql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Playground

func Playground(endpoint string) string

Playground 返回 GraphQL Playground HTML

func PlaygroundHandler

func PlaygroundHandler(endpoint string) router.HandlerFunc

PlaygroundHandler GraphQL Playground 处理器

Types

type Argument

type Argument struct {
	Type         string
	DefaultValue interface{}
}

Argument 参数

type Builder

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

Builder Schema 构建器

func NewBuilder

func NewBuilder() *Builder

NewBuilder 创建构建器

func (*Builder) Build

func (b *Builder) Build() *Schema

Build 构建 Schema

func (*Builder) Mutation

func (b *Builder) Mutation(name string, field *Field) *Builder

Mutation 添加变更字段

func (*Builder) Query

func (b *Builder) Query(name string, field *Field) *Builder

Query 添加查询字段

func (*Builder) Type

func (b *Builder) Type(obj *Object) *Builder

Type 添加类型

type Field

type Field struct {
	Type        string
	Description string
	Args        map[string]*Argument
	Resolve     Resolver
}

Field GraphQL 字段

type GraphQLError

type GraphQLError struct {
	Message string   `json:"message"`
	Path    []string `json:"path,omitempty"`
}

GraphQLError GraphQL 错误

type Object

type Object struct {
	Name        string
	Description string
	Fields      map[string]*Field
}

Object GraphQL 对象类型

type Request

type Request struct {
	Query         string                 `json:"query"`
	OperationName string                 `json:"operationName,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty"`
}

Request GraphQL 请求

type Resolver

type Resolver func(ctx context.Context, args map[string]interface{}) (interface{}, error)

Resolver 解析器函数

type Response

type Response struct {
	Data   interface{}    `json:"data,omitempty"`
	Errors []GraphQLError `json:"errors,omitempty"`
}

Response GraphQL 响应

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

MarshalJSON 自定义 JSON 序列化

type Schema

type Schema struct {
	Query    *Object
	Mutation *Object
	Types    map[string]*Object
}

Schema GraphQL Schema

func NewSchema

func NewSchema() *Schema

NewSchema 创建 Schema

func (*Schema) AddMutation

func (s *Schema) AddMutation(name string, field *Field)

AddMutation 添加变更

func (*Schema) AddQuery

func (s *Schema) AddQuery(name string, field *Field)

AddQuery 添加查询

func (*Schema) AddType

func (s *Schema) AddType(obj *Object)

AddType 添加类型

type Server

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

Server GraphQL 服务器

func NewServer

func NewServer(schema *Schema) *Server

NewServer 创建 GraphQL 服务器

func (*Server) Execute

func (s *Server) Execute(ctx context.Context, req Request) Response

Execute 执行 GraphQL 查询

func (*Server) Handler

func (s *Server) Handler() router.HandlerFunc

Handler 返回 HTTP 处理器

Jump to

Keyboard shortcuts

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