From f42cf79443fd08f61385761f86ddeb0f914257e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 19 Jul 2018 15:27:55 +0200 Subject: [PATCH] start of a graphql schema+types --- graphql/resolvers.go | 7 +++++++ graphql/schema.go | 18 ++++++++++------- graphql/types.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 graphql/resolvers.go create mode 100644 graphql/types.go diff --git a/graphql/resolvers.go b/graphql/resolvers.go new file mode 100644 index 0000000000000000000000000000000000000000..ef20d0f24adfb59df0074d909d893c3582a87ac8 --- /dev/null +++ b/graphql/resolvers.go @@ -0,0 +1,7 @@ +package graphql + +import "github.com/graphql-go/graphql" + +func resolveBug(p graphql.ResolveParams) (interface{}, error) { + return "world", nil +} diff --git a/graphql/schema.go b/graphql/schema.go index f6523f0317eb79f930a30bbf0f5bc546a4651e09..f8fb976852bd2fdd1719ae7f0255adf83ccbaa0b 100644 --- a/graphql/schema.go +++ b/graphql/schema.go @@ -3,15 +3,19 @@ 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: graphql.Fields{ + "hello": &graphql.Field{ + Type: graphql.String, }, }, } - rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} - schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} + + schemaConfig := graphql.SchemaConfig{ + Query: graphql.NewObject(rootQuery), + } + return graphql.NewSchema(schemaConfig) } diff --git a/graphql/types.go b/graphql/types.go new file mode 100644 index 0000000000000000000000000000000000000000..edce9ea151ac546e8e47e90fc2c53f6db8de3e9e --- /dev/null +++ b/graphql/types.go @@ -0,0 +1,48 @@ +package graphql + +import "github.com/graphql-go/graphql" + +// Internally, it's the Snapshot +var bugType = graphql.NewObject(graphql.ObjectConfig{ + Name: "Bug", + Fields: graphql.Fields{ + "id": &graphql.Field{ + Type: graphql.String, + }, + "status": &graphql.Field{ + Type: graphql.String, + }, + "comments": &graphql.Field{ + Type: graphql.NewList(commentType), + }, + "labels": &graphql.Field{ + Type: graphql.NewList(graphql.String), + }, + // TODO: operations + }, +}) + +var commentType = graphql.NewObject(graphql.ObjectConfig{ + Name: "Comment", + Fields: graphql.Fields{ + "author": &graphql.Field{ + Type: personType, + }, + "message": &graphql.Field{ + Type: graphql.String, + }, + // TODO: time + }, +}) + +var personType = graphql.NewObject(graphql.ObjectConfig{ + Name: "Person", + Fields: graphql.Fields{ + "name": &graphql.Field{ + Type: graphql.String, + }, + "email": &graphql.Field{ + Type: graphql.String, + }, + }, +})