samsarahq / thunder

⚡️ A Go framework for rapidly building powerful graphql services

Home Page:https://godoc.org/github.com/samsarahq/thunder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not use int in args input

sijad opened this issue · comments

I'm trying to use int as an input type but when I run following code it panics:

panic: bad method echo on type schemabuilder.mutation: attempted to parse  as arguments struct, but failed: bad arg type int: should be struct, scalar, pointer, or a slice

goroutine 1 [running]:
github.com/samsarahq/thunder/graphql/schemabuilder.(*Schema).MustBuild(...)
	/home/o/go/src/github.com/samsarahq/thunder/graphql/schemabuilder/schema.go:281
main.(*server).schema(0xc0001d1f78, 0x0)
	/home/o/go/src/github.com/sijad/testthunder/main.go:28 +0x86
main.main()
	/home/o/go/src/github.com/sijad/testthunder/main.go:34 +0x2f
exit status 2

MRE

package main

import (
	"net/http"

	"github.com/samsarahq/thunder/graphql"
	"github.com/samsarahq/thunder/graphql/schemabuilder"
)

// server is our graphql server.
type server struct{}

// registerMutation registers the root mutation type.
func (s *server) registerMutation(schema *schemabuilder.Schema) {
	obj := schema.Mutation()
	obj.FieldFunc("echo", func(args struct {
		Message    string
		MyIntValue int
	}) string {
		return args.Message
	})
}

// schema builds the graphql schema.
func (s *server) schema() *graphql.Schema {
	builder := schemabuilder.NewSchema()
	s.registerMutation(builder)
	return builder.MustBuild()
}

func main() {
	server := &server{}

	schema := server.schema()

	// Expose schema and graphiql.
	http.Handle("/graphql", graphql.Handler(schema))
	http.ListenAndServe(":3030", nil)
}

when I remove MyIntValue int, it works fine

it seems like int is missing in the arg parser struct here:

var scalarArgParsers = map[reflect.Type]*argParser{

(internally, we tend to use fixed size ints)

could you send a PR?