package module
Version: v2.0.0+incompatible Latest Latest

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

Go to latest
Published: Sep 7, 2019 License: MIT Imports: 5 Imported by: 2


Go Report Card


  1. Convert Golang Struct To GraphQL Object On The Fly
  2. Easily Create GraphQL Schemas


Converting struct to GraphQL Object
type UserExtra struct {
    Age int `description:"Age of the user"` //You can use description struct tag to add description
    Gender string `deprecationReason:"Some Reason"` // You can use deprecationReason tag to add a deprecation reason

type User struct {
    UserID int
    Username string `unique:"true"` // You can use unique tag to define if a field would be unique
    Extra UserExtra

func main() {
    //GetGraphQLObject will convert golang struct to a graphQL object
    userType, err := straf.GetGraphQLObject(User{})

    //You can then use userType in your graphQL schema
Using The Schema Builder
type User struct {
    UserID int `isArg:"true"` //You can use isArg tag to define a field as a graphql argument
    Username string `isArg:"true"`

var database []User = []User{}

func main() {
    //GetGraphQLObject will convert golang struct to a graphQL object
    userType, err := straf.GetGraphQLObject(User{})

    builder := straf.NewSchemaBuilder(userType, User{})
                        "Adds a user to database",
                        func(params graphql.ResolveParams) (interface{}, error)) {
                            id := params.Args["UserID"]
                            username := params.Args["Username"]
                            database = append(database, User{UserID: id, Username: Username})
    schema := builder.Schema
    //You can then use this schema




This section is empty.


This section is empty.


func GetGraphQLObject

func GetGraphQLObject(object interface{}) (*graphql.Object, error)

GetGraphQLObject Converts struct into graphql object


type SchemaBuilder

type SchemaBuilder struct {
	GraphQLType graphql.Output
	Object      interface{}
	Schema      graphql.Fields
	// contains filtered or unexported fields

SchemaBuilder is used to build a schema based on a struct

func NewSchemaBuilder

func NewSchemaBuilder(graphQLType graphql.Output, object interface{}) *SchemaBuilder

NewSchemaBuilder is used get a new schema builder

func (*SchemaBuilder) AddFunction

func (schemaBuilder *SchemaBuilder) AddFunction(
	description string,
	function func(graphql.ResolveParams) (interface{}, error))

AddFunction adds a function

func (*SchemaBuilder) Init

func (schemaBuilder *SchemaBuilder) Init() error

Init initializes

Jump to

Keyboard shortcuts

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