graphqlgo

package module
v0.0.0-...-042d8fe Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Graphql Go

golang graphql framework inspired by type-graphql.

Get Started

import (
    "encoding/json"

    "github.com/gin-gonic/gin"
    graphqlGo"github.com/onichandame/graphql-go"
    graphql "github.com/graphql-go/graphql"
)

type User struct{
    Name string `graphqlgo:"name=name,type=string"`
}

var users = make([]*User,0)

type UserInput struct{
    Input *User `graphqlgo:"name=input"`
}

func (u*User)MutationcreateUser(ctx *gin.Context, args *UserInput)*User{
    users=append(users,args.Input)
    return users[len(users)-1]
}

func main(){
    schema:=graphqlGo.GetSchemaFromStruct(&User{})
    http.HandleFunc("/graphql",func(w http.ResponseWriter,r*http.Request){
        query:=r.URL.Query().Get("query")
        result:=graphql.Do(graphql.Params{
            Schema: schema,
            RequestString:query,
        })
        json.NewEncoder(w).Encode(result)
    })
    http.ListenAndServe(":80",nil)
}

Documentation

Index

Constants

View Source
const (
	INPUT  typeCategory = iota
	OUTPUT typeCategory = iota
)
View Source
const (
	QUERY_PREFIX        = "Query"
	MUTATION_PREFIX     = "Mutation"
	SUBSCRIPTION_PREFIX = "Subscription"
)
View Source
const TAG_KEY = "graphqlgo"

Variables

View Source
var CustomInObjects = make(map[reflect.Type]*graphql.InputObject)
View Source
var CustomOutObjects = make(map[reflect.Type]*graphql.Object)

Functions

func GetSchema

func GetSchema(props SchemaConfig) *graphql.Schema

Types

type SchemaConfig

type SchemaConfig struct {
	Resolvers []interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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