1package graphql
2
3import (
4 "github.com/MichaelMure/git-bug/bug"
5 "github.com/MichaelMure/git-bug/repository"
6 "github.com/graphql-go/graphql"
7)
8
9func graphqlSchema() (graphql.Schema, error) {
10 fields := graphql.Fields{
11 "bug": &graphql.Field{
12 Type: bugType,
13 Args: graphql.FieldConfigArgument{
14 "id": &graphql.ArgumentConfig{
15 Type: bugIdScalar,
16 },
17 },
18 Resolve: func(p graphql.ResolveParams) (interface{}, error) {
19 repo := p.Context.Value("repo").(repository.Repo)
20 id, _ := p.Args["id"].(string)
21 bug, err := bug.FindBug(repo, id)
22 if err != nil {
23 return nil, err
24 }
25
26 snapshot := bug.Compile()
27
28 return snapshot, nil
29 },
30 },
31 }
32 rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields}
33 schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
34 return graphql.NewSchema(schemaConfig)
35}