Last active
January 19, 2018 09:08
-
-
Save darkodemic/a1d367cc1fa3db88b36d32298f4f8512 to your computer and use it in GitHub Desktop.
Go and GraphQL - Main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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