graphql

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 9 Imported by: 0

README

graphql-http

graphql http api

使用示例

  • gin工程中
// service.go
package service

import (
	"embed"
	"github.com/aide-cloud/graphql-http"
	"github.com/gin-gonic/gin"
)

type GraphqlService struct {}

type Root struct {}

func (r *Root) Ping() string {
	return "pong"
}

// Content holds all the SDL file content.
//go:embed sdl
var content embed.FS

func NewRoot() *Root {
	return &Root{}
}

func NewGraphqlService() *GraphqlService {
	return &GraphqlService{}
}

func (g *GraphqlService) RegisterGraphqlGinRouter(root *Root, r *gin.Engine) {
	r.GET("/query", gin.WrapF(graphql.NewGraphQLNetHttpHandlerFunc("/graphql")))
	r.POST("/graphql", gin.WrapH(graphql.NewNetHttpHandler(root, content)))
}

# root.graphql
schema {
    query: RootQuery
}

type RootQuery {
    ping: String!
}

  • 目录结构
.
├── README.md
├── sdl
│   └── root.graphql
├── service.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGraphQKratosHttpLHandlerFunc

func NewGraphQKratosHttpLHandlerFunc(mutationPath string) http.HandlerFunc

func NewGraphQLNetHttpHandlerFunc

func NewGraphQLNetHttpHandlerFunc(mutationPath string) nHttp.HandlerFunc

func NewKratosHttpHandler

func NewKratosHttpHandler(root any, content embed.FS) http.HandlerFunc

func NewNetHttpHandler

func NewNetHttpHandler(root any, content embed.FS) *relay.Handler

func String

func String(content embed.FS) (string, error)

String reads the .graphql schema files from the embed.FS, concatenating the files together into one string.

If this method complains about not finding functions AssetNames() or MustAsset(), run `go generate` against this package to generate the functions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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