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
+}
Michael Muré created
graphql/resolvers.go | 7 ++++++
graphql/schema.go | 18 ++++++++++------
graphql/types.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 7 deletions(-)
@@ -0,0 +1,7 @@
+package graphql
+
+import "github.com/graphql-go/graphql"
+
+func resolveBug(p graphql.ResolveParams) (interface{}, error) {
+ return "world", nil
+}
@@ -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)
}
@@ -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,
+ },
+ },
+})