diff options
author | Quentin Gliech <quentingliech@gmail.com> | 2018-07-22 01:12:44 +0200 |
---|---|---|
committer | Quentin Gliech <quentingliech@gmail.com> | 2018-07-22 01:12:44 +0200 |
commit | 50fd2943acac8685db92a016ee3c9dbfc95842cf (patch) | |
tree | db37beb3cb3fa8d6a7abb01afb1009643457626d /graphql | |
parent | 4901bdadd3918833fc2cf0ad47d73aeeb061af0d (diff) | |
download | git-bug-50fd2943acac8685db92a016ee3c9dbfc95842cf.tar.gz |
graphql: add `allBugs` to root query
Diffstat (limited to 'graphql')
-rw-r--r-- | graphql/schema.go | 26 |
1 files changed, 26 insertions, 0 deletions
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)} |