hgraph

package module
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hgraph

golang 结构体添加自定义标签的方式开发Graphql服务。

// Query结构体示例
type Query struct {
	Member Member `graphql:"!member" description:"会员服务"`
	Version string
}

// 顶级结构体只有Query与Mutation 
// 通过往结构体加属性,可层层嵌套,与Graphql Schema结构一致。
// 结构体对应graphql.NewOject, 结构体字段对应graphql.Field 
// Http服务 使用Handel 
http.ListenAndServe(":9990", hgraph.GraphqlHttpHandler(Query{}, Mutation{}))

Features

  1. 结构体自定义标签方式实现Graphql schema。
  2. 基于Host DNS的方式实现微服务调用(使用docker集群或者改为注册中心等方式实现),Query 与 Mutation 对象的一级字段作为为服务名,子集为业务字段。
  3. 微服务,客户端可一次请求多个业务服务,合并结果数据返回,多服务对前端无感知。

Change Log

v0.1.0

  • 使用Go结构体的方式构建Graphql schema

Documentation

Overview

Graphql 类型缩写, 减少Schema代码量

Index

Constants

This section is empty.

Variables

View Source
var GraphqlSchema = func(query, mutation interface{}) *graphql.Schema {
	newSchema, err := graphql.NewSchema(graphql.SchemaConfig{
		Query:        GraphqlObject(query),
		Mutation:     GraphqlObject(mutation),
		Subscription: nil,
		Types:        nil,
		Directives:   nil,
		Extensions:   nil,
	})
	if err != nil {

		log.Fatal(err)
	}
	log.Printf("GraphqlSchema Load Success")
	return &newSchema
}

Graphql Schema

Functions

func Gateway added in v0.0.3

func Gateway(requestBody []byte) []byte

网关调用服务

func GraphqlHttpHandler

func GraphqlHttpHandler(query, mutation interface{}) *handler.Handler

Http Handler h := hgraph.GraphqlHttpHandler(&Query{}, &Mutation{})

func GraphqlObject added in v0.1.0

func GraphqlObject(i interface{}) *graphql.Object

i = Query{} i = Mutation{}

func GraphqlType added in v0.1.0

func GraphqlType(t reflect.Type) graphql.Type

object := Query{} objectType := reflect.TypeOf(object)

func HttpClient added in v0.1.13

func HttpClient() *http.Client

func HttpHandle added in v0.1.13

func HttpHandle(query, mutation interface{})

func ParseGraphqlQuery added in v0.0.3

func ParseGraphqlQuery(query string) map[string]string

解析Graphql 字符串,第一级Key作为服务名,value拼接为查询字符串

Types

type GraphRequestModel added in v0.0.3

type GraphRequestModel struct {
	RequestId     string      `json:"requestId"`
	Token         string      `json:"token"`
	OperationName string      `json:"operationName"`
	Query         string      `json:"query"`
	Variables     interface{} `json:"variables"`
}

Graphql 请求JSON Model

func ParseGraphqlReuqest added in v0.0.3

func ParseGraphqlReuqest(b []byte) (*GraphRequestModel, error)

type GraphResponseModel added in v0.0.3

type GraphResponseModel struct {
	RequestId string                   `json:"requestId"`
	HostTime  string                   `json:"hostTime"`
	Data      map[string]interface{}   `json:"data"`
	Errors    []map[string]interface{} `json:"errors,omitempty"`
}

Graphql 响应JSON Model

func BulkRequest added in v0.0.3

func BulkRequest(reqModel *GraphRequestModel, services map[string]string) *GraphResponseModel

批量请求Graphql服务响应报文,合并响应结果返回

func Feign added in v0.1.0

func Feign(reqModel *GraphRequestModel) (resModel *GraphResponseModel)

调用业务服务 解析请求字符串第一级字段作为服务名调用Graphql服务

func PostGraphqlService added in v0.1.0

func PostGraphqlService(name string, requestModel *GraphRequestModel) (resModel *GraphResponseModel)

根据服务名调用服务 bytes 为http请求响应body message 为错误消息

func (*GraphResponseModel) FirstErrorMessage added in v0.1.3

func (r *GraphResponseModel) FirstErrorMessage() error

返回第一条错误内容

func (*GraphResponseModel) ToStruct added in v0.1.3

func (r *GraphResponseModel) ToStruct(serviceName string, output interface{})

转为结构体

type ResolveParams added in v0.1.0

type ResolveParams graphql.ResolveParams

扩展Graphql Resolve函数的参数方法

func (ResolveParams) Auth added in v0.1.0

func (ResolveParams) Auth()

type Tag added in v0.1.0

type Tag struct {
	Graphql           string
	Description       string
	DeprecationReason string
	DefaultValue      string
}

type Time added in v0.1.0

type Time time.Time

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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