diff --git a/execution.go b/execution.go index 3fc7057..6c40a8f 100644 --- a/execution.go +++ b/execution.go @@ -756,6 +756,16 @@ func defaultResolver(fname string) Resolver { return func(ctx Context) (interface{}, error) { t := reflect.TypeOf(ctx.Parent()) v := reflect.ValueOf(ctx.Parent()) + + if t.Kind() == reflect.Ptr { + t = t.Elem() + v = v.Elem() + } + + if t.Kind() != reflect.Struct { + return nil, nil + } + for i := 0; i < t.NumField(); i++ { // Get the field, returns https://golang.org/pkg/reflect/#StructField field := t.Field(i) @@ -930,11 +940,12 @@ func completeValue(ctx *gqlCtx, path []interface{}, ft Type, fs ast.Fields, resu func getTypes(s *Schema) (map[string]Type, map[string]Directive, map[string][]Type) { types := map[string]Type{ - "String": String, - "Boolean": Boolean, - "Int": Int, - "ID": ID, - "Float": Float, + "String": String, + "Boolean": Boolean, + "Int": Int, + "ID": ID, + "Float": Float, + "DateTime": DateTime, } directives := map[string]Directive{ "skip": skipDirective, @@ -974,7 +985,7 @@ func typeWalker(types map[string]Type, directives map[string]Directive, implemen return } // TODO: directives are not checked and "walked" through - if hf, ok := t.(hasFields); ok { + if hf, ok := wt.(hasFields); ok { if o, ok := t.(*Object); ok { for _, i := range o.Implements { if os, ok := implementors[i.Name]; ok { @@ -987,15 +998,19 @@ func typeWalker(types map[string]Type, directives map[string]Directive, implemen } } for _, f := range hf.GetFields() { - for _, arg := range f.GetArguments() { + for _, arg := range f.Arguments { typeWalker(types, directives, implementors, arg.Type) } - typeWalker(types, directives, implementors, f.GetType()) + typeWalker(types, directives, implementors, f.Type) } } else if u, ok := wt.(*Union); ok { - for _, m := range u.GetMembers() { + for _, m := range u.Members { typeWalker(types, directives, implementors, m) } + } else if io, ok := wt.(*InputObject); ok { + for _, f := range io.Fields { + typeWalker(types, directives, implementors, f.Type) + } } } diff --git a/introspection.go b/introspection.go index 832f03a..51467a5 100644 --- a/introspection.go +++ b/introspection.go @@ -1,5 +1,9 @@ package gql +import ( + "encoding/json" +) + func init() { typeIntrospection.AddField( "interfaces", @@ -403,12 +407,27 @@ var ( Type: String, Resolver: func(ctx Context) (interface{}, error) { if v, ok := ctx.Parent().(*iArgument); ok && v.arg.IsDefaultValueSet() { - return v.arg.DefaultValue, nil - } else if v, ok := ctx.Parent().(struct { - field *InputField - name string - }); ok && v.field.IsDefaultValueSet() { - return v.field.DefaultValue, nil + if unwrapper(v.arg.Type).GetKind() == EnumKind { + return v.arg.DefaultValue, nil + } + if v.arg.DefaultValue != nil { + bs, err := json.Marshal(v.arg.DefaultValue) + if err != nil { + return nil, err + } + return string(bs), nil + } + } else if v, ok := ctx.Parent().(iInputField); ok && v.field.IsDefaultValueSet() { + if unwrapper(v.field.Type).GetKind() == EnumKind { + return v.field.DefaultValue, nil + } + if v.field.DefaultValue != nil { + bs, err := json.Marshal(v.field.DefaultValue) + if err != nil { + return nil, err + } + return string(bs), nil + } } return nil, nil },