diff options
author | Michael Muré <batolettre@gmail.com> | 2018-07-19 14:15:50 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-07-19 14:15:50 +0200 |
commit | a2a50f3de0c428c5a61e6a449191be3c4ded86ac (patch) | |
tree | 5ecf4f5f1f26933b42a606b741963fa5f66c85aa /graphql | |
parent | 25fb88d7497b00bbe3dda540efde22ffd3de6e49 (diff) | |
download | git-bug-a2a50f3de0c428c5a61e6a449191be3c4ded86ac.tar.gz |
webui: add a primitive graphql handler
Diffstat (limited to 'graphql')
-rw-r--r-- | graphql/handler.go | 17 | ||||
-rw-r--r-- | graphql/schema.go | 17 |
2 files changed, 34 insertions, 0 deletions
diff --git a/graphql/handler.go b/graphql/handler.go new file mode 100644 index 00000000..4843fff9 --- /dev/null +++ b/graphql/handler.go @@ -0,0 +1,17 @@ +package graphql + +import "github.com/graphql-go/handler" + +func NewHandler() (*handler.Handler, error) { + schema, err := graphqlSchema() + + if err != nil { + return nil, err + } + + return handler.New(&handler.Config{ + Schema: &schema, + Pretty: true, + GraphiQL: true, + }), nil +} diff --git a/graphql/schema.go b/graphql/schema.go new file mode 100644 index 00000000..f6523f03 --- /dev/null +++ b/graphql/schema.go @@ -0,0 +1,17 @@ +package graphql + +import "github.com/graphql-go/graphql" + +func graphqlSchema() (graphql.Schema, error) { + fields := graphql.Fields{ + "hello": &graphql.Field{ + Type: graphql.String, + Resolve: func(p graphql.ResolveParams) (interface{}, error) { + return "world", nil + }, + }, + } + rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} + schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} + return graphql.NewSchema(schemaConfig) +} |