From 652e6ea5533f37c596bab8a29a9f888958541cad Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Fri, 10 Jan 2025 17:03:12 +0100 Subject: [PATCH] added author --- internal/web/gqlSchema.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/web/gqlSchema.go b/internal/web/gqlSchema.go index 372533f..29bcc44 100644 --- a/internal/web/gqlSchema.go +++ b/internal/web/gqlSchema.go @@ -36,6 +36,22 @@ func createShema(repo repo.Repo) graphql.Schema { "score": &graphql.Field{ Type: graphql.NewNonNull(graphql.Int), }, + "author": &graphql.Field{ + Type: graphql.NewNonNull(player), + Resolve: func(p graphql.ResolveParams) (interface{}, error) { + game, ok := p.Source.(*model.Game) + if !ok { + return nil, nil + } + + player, err := repo.GetPlayer(game.Author) + if err != nil { + return nil, err + } + + return player, nil + }, + }, "team0player0": &graphql.Field{ Type: graphql.NewNonNull(player), Resolve: func(p graphql.ResolveParams) (interface{}, error) { @@ -170,7 +186,7 @@ func createShema(repo repo.Repo) graphql.Schema { Resolve: func(p graphql.ResolveParams) (interface{}, error) { id, ok := p.Args["id"].(string) if !ok { - log.Println("Failed to parse ID at player: %v", p.Args["id"]) + log.Println("Failed to parse ID at player: %v", p.Args["id"]) return nil, nil } @@ -193,7 +209,7 @@ func createShema(repo repo.Repo) graphql.Schema { Resolve: func(p graphql.ResolveParams) (interface{}, error) { id, ok := p.Args["id"].(string) if !ok { - log.Println("Failed to parse ID at game: %v", p.Args["id"]) + log.Println("Failed to parse ID at game: %v", p.Args["id"]) return nil, nil } @@ -216,7 +232,7 @@ func createShema(repo repo.Repo) graphql.Schema { Resolve: func(p graphql.ResolveParams) (interface{}, error) { id, ok := p.Args["id"].(string) if !ok { - log.Println("Failed to parse ID at gameResult: %v", p.Args["id"]) + log.Println("Failed to parse ID at gameResult: %v", p.Args["id"]) return nil, nil }