func (app *App) RunServer() { g := graph.NewGraph() schema := schema.New() schema.Register(g) executor := executor.New(schema) handler := handler.New(executor) mux := http.NewServeMux() mux.Handle("/", handler) log.Fatalln(http.ListenAndServe(app.address, mux)) }
func main() { flag.Parse() // create a new schema (which self-registers) now := &nowProvider{time.Now()} schema := schema.New() schema.Register(now) executor := executor.New(schema) handler := handler.New(executor) mux := http.NewServeMux() mux.Handle("/", handler) log.Fatalln(http.ListenAndServe(*listenAddr, mux)) }
func (c *ServeOptions) Execute(args []string) error { log.Println(c) schema := schema.New() client, err := parse.NewClient(c.ParseApplicationID, c.ParseRESTAPIKey) if err != nil { return err } mClient := client.WithMasterKey(c.ParseMasterKey) client.TraceOn(log.New(os.Stdout, "[parse] ", log.LstdFlags)) classes, err := mClient.GetFullSchema() if err != nil { return fmt.Errorf("error fetching parse app schema: %v", err) } hooks, err := mClient.GetHookFunctions() if err != nil { return fmt.Errorf("error fetching parse app hooks: %v", err) } parseSchema, err := parse_graphql.NewParseSchema(client, classes, hooks) if err != nil { return err } for _, class := range parseSchema.Schema { parseClass, err := parse_graphql.NewParseClass(client, class.ClassName, parseSchema.Schema) if err != nil { return err } schema.Register(parseClass) } schema.Register(parseSchema) // for top-level fields executor := executor.New(schema) mux := http.NewServeMux() mux.Handle("/", handler.New(executor)) return http.ListenAndServe(c.ListenAddr, mux) }