aboutsummaryrefslogtreecommitdiffstats
path: root/graphql
diff options
context:
space:
mode:
Diffstat (limited to 'graphql')
-rw-r--r--graphql/handler.go17
-rw-r--r--graphql/schema.go17
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)
+}