diff options
Diffstat (limited to 'graphql/schema.go')
-rw-r--r-- | graphql/schema.go | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/graphql/schema.go b/graphql/schema.go index e929fb44..4cb893fe 100644 --- a/graphql/schema.go +++ b/graphql/schema.go @@ -1,21 +1,35 @@ package graphql -import "github.com/graphql-go/graphql" +import ( + "github.com/MichaelMure/git-bug/bug" + "github.com/MichaelMure/git-bug/repository" + "github.com/graphql-go/graphql" +) -func newGraphqlSchema() (graphql.Schema, error) { +func graphqlSchema() (graphql.Schema, error) { + fields := graphql.Fields{ + "bug": &graphql.Field{ + Type: bugType, + Args: graphql.FieldConfigArgument{ + "id": &graphql.ArgumentConfig{ + Type: bugIdScalar, + }, + }, + Resolve: func(p graphql.ResolveParams) (interface{}, error) { + repo := p.Context.Value("repo").(repository.Repo) + id, _ := p.Args["id"].(string) + bug, err := bug.FindBug(repo, id) + if err != nil { + return nil, err + } + + snapshot := bug.Compile() - rootQuery := graphql.ObjectConfig{ - Name: "RootQuery", - Fields: graphql.Fields{ - "hello": &graphql.Field{ - Type: graphql.String, + return snapshot, nil }, }, } - - schemaConfig := graphql.SchemaConfig{ - Query: graphql.NewObject(rootQuery), - } - + rootQuery := graphql.ObjectConfig{Name: "RootQuery", Fields: fields} + schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)} return graphql.NewSchema(schemaConfig) } |