flamingo.me/flamingo-commerce/v3@v3.11.0/test/integrationtest/projecttest/graphql/module.go (about) 1 // Code generated by flamingo.me/graphql, DO NOT EDIT. 2 //go:build !graphql 3 // +build !graphql 4 5 package graphql 6 7 import ( 8 "context" 9 "encoding/json" 10 "log" 11 "reflect" 12 13 "flamingo.me/dingo" 14 "github.com/99designs/gqlgen/graphql" 15 "github.com/spf13/cobra" 16 ) 17 18 // Module is an autogenerated dingo Module to bind the root resolver 19 type Module struct{} 20 21 // Configure sets the graphql.ExecutableSchema binding via a provider, passing in the correct root resolver 22 func (*Module) Configure(injector *dingo.Injector) { 23 injector.Bind(new(graphql.ExecutableSchema)).ToProvider(func(root *rootResolver) graphql.ExecutableSchema { 24 return NewExecutableSchema(Config{Resolvers: root, Directives: root.directives()}) 25 }) 26 27 injector.BindMulti(new(cobra.Command)).ToProvider(func(root *rootResolver) *cobra.Command { 28 return &cobra.Command{ 29 Use: "gql calls a gql function like 'go run main.go gql User.Todos '{\"Name\":\"User a\"}' ", 30 Run: func(cmd *cobra.Command, args []string) { 31 if len(args) == 0 { 32 for k := range direct(root) { 33 log.Println(k) 34 } 35 return 36 } else if len(args) == 1 { 37 v := reflect.ValueOf(direct(root)[args[0]]) 38 log.Printf("%s", v.Type().String()) 39 return 40 } 41 42 v := reflect.ValueOf(direct(root)[args[0]]) 43 in := make([]reflect.Value, v.Type().NumIn()-1) 44 for i := 1; i < v.Type().NumIn(); i++ { 45 in[i-1] = reflect.New(v.Type().In(i)) 46 log.Println(json.Unmarshal([]byte(args[i]), in[i-1].Interface())) 47 in[i-1] = in[i-1].Elem() 48 } 49 res := v.Call(append([]reflect.Value{reflect.ValueOf(context.Background())}, in...)) 50 for _, r := range res { 51 v, _ := json.Marshal(r.Interface()) 52 log.Print(string(v)) 53 } 54 }, 55 } 56 }) 57 }