Skip to content

Instantly share code, notes, and snippets.

@darkodemic
Last active January 19, 2018 09:08
Show Gist options
  • Save darkodemic/a1d367cc1fa3db88b36d32298f4f8512 to your computer and use it in GitHub Desktop.
Save darkodemic/a1d367cc1fa3db88b36d32298f4f8512 to your computer and use it in GitHub Desktop.
Go and GraphQL - Main
package main
import (
"github.com/graphql-go/graphql-go-handler"
"github.com/graphql-go/graphql"
"net/http"
)
var queryType = graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"fieldName": &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return "Hi there!", nil
},
},
},
})
var Schema, _ = graphql.NewSchema(graphql.SchemaConfig{
Query: queryType,
})
func main() {
h := handler.New(&handler.Config{
Schema: &Schema,
Pretty: true,
GraphiQL: true,
})
// serve a GraphQL endpoint at `/`
http.Handle("/", h)
// Serve it at localhost:8080
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment