From 3dd41e5da17c41d24fe295819b3717e5ae47794d Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sun, 22 Jul 2018 00:17:22 +0200 Subject: Add title field to bugs in graphql schema --- graphql/types.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'graphql') diff --git a/graphql/types.go b/graphql/types.go index a320ca39..f1161687 100644 --- a/graphql/types.go +++ b/graphql/types.go @@ -43,6 +43,9 @@ var bugType = graphql.NewObject(graphql.ObjectConfig{ "status": &graphql.Field{ Type: graphql.String, }, + "title": &graphql.Field{ + Type: graphql.String, + }, "comments": &graphql.Field{ Type: graphql.NewList(commentType), }, -- cgit From 50fd2943acac8685db92a016ee3c9dbfc95842cf Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Sun, 22 Jul 2018 01:12:44 +0200 Subject: graphql: add `allBugs` to root query --- graphql/schema.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'graphql') diff --git a/graphql/schema.go b/graphql/schema.go index 4cb893fe..7419e98a 100644 --- a/graphql/schema.go +++ b/graphql/schema.go @@ -28,6 +28,32 @@ func graphqlSchema() (graphql.Schema, error) { return snapshot, nil }, }, + // TODO: provide a relay-like schema with pagination + "allBugs": &graphql.Field{ + Type: graphql.NewList(bugType), + Resolve: func(p graphql.ResolveParams) (interface{}, error) { + repo := p.Context.Value("repo").(repository.Repo) + ids, err := repo.ListRefs(bug.BugsRefPattern) + + if err != nil { + return nil, err + } + + var snapshots []bug.Snapshot + + for _, ref := range ids { + bug, err := bug.ReadBug(repo, bug.BugsRefPattern+ref) + + if err != nil { + return nil, err + } + + snapshots = append(snapshots, bug.Compile()) + } + + return snapshots, nil + }, + }, } rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} -- cgit