M database/schema.go => database/schema.go +3 -1
@@ 14,7 14,9 @@ CREATE TABLE "User" (
teamspeak_id VARCHAR(255) NOT NULL UNIQUE,
elo SMALLINT NOT NULL,
admin BOOLEAN NOT NULL DEFAULT FALSE,
- queueing BOOLEAN NOT NULL DEFAULT FALSE
+ queueing BOOLEAN NOT NULL DEFAULT FALSE,
+ avatar VARCHAR(255),
+ name VARCHAR(255)
);
CREATE TABLE "Team" (
M graph/generated/generated.go => graph/generated/generated.go +104 -0
@@ 59,8 59,10 @@ type ComplexityRoot struct {
User struct {
Admin func(childComplexity int) int
+ Avatar func(childComplexity int) int
Elo func(childComplexity int) int
ID func(childComplexity int) int
+ Name func(childComplexity int) int
SteamID func(childComplexity int) int
TeamspeakID func(childComplexity int) int
}
@@ 205,6 207,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.User.Admin(childComplexity), true
+ case "User.avatar":
+ if e.complexity.User.Avatar == nil {
+ break
+ }
+
+ return e.complexity.User.Avatar(childComplexity), true
+
case "User.elo":
if e.complexity.User.Elo == nil {
break
@@ 219,6 228,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.User.ID(childComplexity), true
+ case "User.name":
+ if e.complexity.User.Name == nil {
+ break
+ }
+
+ return e.complexity.User.Name(childComplexity), true
+
case "User.steamID":
if e.complexity.User.SteamID == nil {
break
@@ 303,6 319,8 @@ var sources = []*ast.Source{
teamspeakID: String!
elo: Int!
admin: Boolean!
+ avatar: String
+ name: String
}
type Query {
@@ 313,6 331,8 @@ type Query {
input NewUser {
steamID: String!
teamspeakID: String!
+ avatar: String
+ name: String
}
type Mutation {
@@ 1125,6 1145,70 @@ func (ec *executionContext) _User_admin(ctx context.Context, field graphql.Colle
return ec.marshalNBoolean2bool(ctx, field.Selections, res)
}
+func (ec *executionContext) _User_avatar(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) {
+ defer func() {
+ if r := recover(); r != nil {
+ ec.Error(ctx, ec.Recover(ctx, r))
+ ret = graphql.Null
+ }
+ }()
+ fc := &graphql.FieldContext{
+ Object: "User",
+ Field: field,
+ Args: nil,
+ IsMethod: false,
+ IsResolver: false,
+ }
+
+ ctx = graphql.WithFieldContext(ctx, fc)
+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
+ ctx = rctx // use context from middleware stack in children
+ return obj.Avatar, nil
+ })
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ if resTmp == nil {
+ return graphql.Null
+ }
+ res := resTmp.(*string)
+ fc.Result = res
+ return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
+}
+
+func (ec *executionContext) _User_name(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) {
+ defer func() {
+ if r := recover(); r != nil {
+ ec.Error(ctx, ec.Recover(ctx, r))
+ ret = graphql.Null
+ }
+ }()
+ fc := &graphql.FieldContext{
+ Object: "User",
+ Field: field,
+ Args: nil,
+ IsMethod: false,
+ IsResolver: false,
+ }
+
+ ctx = graphql.WithFieldContext(ctx, fc)
+ resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
+ ctx = rctx // use context from middleware stack in children
+ return obj.Name, nil
+ })
+ if err != nil {
+ ec.Error(ctx, err)
+ return graphql.Null
+ }
+ if resTmp == nil {
+ return graphql.Null
+ }
+ res := resTmp.(*string)
+ fc.Result = res
+ return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
+}
+
func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
@@ 2272,6 2356,22 @@ func (ec *executionContext) unmarshalInputNewUser(ctx context.Context, obj inter
if err != nil {
return it, err
}
+ case "avatar":
+ var err error
+
+ ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("avatar"))
+ it.Avatar, err = ec.unmarshalOString2ᚖstring(ctx, v)
+ if err != nil {
+ return it, err
+ }
+ case "name":
+ var err error
+
+ ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name"))
+ it.Name, err = ec.unmarshalOString2ᚖstring(ctx, v)
+ if err != nil {
+ return it, err
+ }
}
}
@@ 2435,6 2535,10 @@ func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null {
invalids++
}
+ case "avatar":
+ out.Values[i] = ec._User_avatar(ctx, field, obj)
+ case "name":
+ out.Values[i] = ec._User_name(ctx, field, obj)
default:
panic("unknown field " + strconv.Quote(field.Name))
}
M graph/model/models_gen.go => graph/model/models_gen.go +11 -7
@@ 3,14 3,18 @@
package model
type NewUser struct {
- SteamID string `json:"steamID"`
- TeamspeakID string `json:"teamspeakID"`
+ SteamID string `json:"steamID"`
+ TeamspeakID string `json:"teamspeakID"`
+ Avatar *string `json:"avatar"`
+ Name *string `json:"name"`
}
type User struct {
- ID int `json:"id"`
- SteamID string `json:"steamID"`
- TeamspeakID string `json:"teamspeakID"`
- Elo int `json:"elo"`
- Admin bool `json:"admin"`
+ ID int `json:"id"`
+ SteamID string `json:"steamID"`
+ TeamspeakID string `json:"teamspeakID"`
+ Elo int `json:"elo"`
+ Admin bool `json:"admin"`
+ Avatar *string `json:"avatar"`
+ Name *string `json:"name"`
}
M graph/schema.graphqls => graph/schema.graphqls +4 -0
@@ 4,6 4,8 @@ type User {
teamspeakID: String!
elo: Int!
admin: Boolean!
+ avatar: String
+ name: String
}
type Query {
@@ 14,6 16,8 @@ type Query {
input NewUser {
steamID: String!
teamspeakID: String!
+ avatar: String
+ name: String
}
type Mutation {
M graph/schema.resolvers.go => graph/schema.resolvers.go +10 -7
@@ 56,9 56,10 @@ func (r *mutationResolver) CreateUser(ctx context.Context, input model.NewUser)
}
query := `
- INSERT INTO "User" (steam_id, teamspeak_id, elo, admin)
- VALUES ($1, $2, $3, $4)`
- _, err = database.DB.Exec(query, input.SteamID, input.TeamspeakID, elo.Elo, isAdmin)
+ INSERT INTO "User" (steam_id, teamspeak_id, elo, admin, avatar, name)
+ VALUES ($1, $2, $3, $4, $5, $6)`
+ _, err = database.DB.Exec(query, input.SteamID, input.TeamspeakID, elo.Elo,
+ isAdmin, input.Avatar, input.Name)
if err != nil {
return "", err
}
@@ 323,10 324,11 @@ func (r *queryResolver) UserBySteam(ctx context.Context, steamID string) (*model
user.SteamID = steamID
query := `
- SELECT id, teamspeak_id, Elo, admin
+ SELECT id, teamspeak_id, Elo, admin, avatar, name
FROM "User"
WHERE steam_id = $1`
- err := database.DB.QueryRow(query, steamID).Scan(&user.ID, &user.TeamspeakID, &user.Elo, &user.Admin)
+ err := database.DB.QueryRow(query, steamID).Scan(&user.ID,
+ &user.TeamspeakID, &user.Elo, &user.Admin, &user.Avatar, &user.Name)
if err != nil {
return nil, err
}
@@ 339,10 341,11 @@ func (r *queryResolver) UserByTs(ctx context.Context, teamspeakID string) (*mode
user.TeamspeakID = teamspeakID
query := `
- SELECT id, steam_id, Elo, admin
+ SELECT id, steam_id, Elo, admin, avatar, name
FROM "User"
WHERE teamspeak_id = $1`
- err := database.DB.QueryRow(query, teamspeakID).Scan(&user.ID, &user.SteamID, &user.Elo, &user.Admin)
+ err := database.DB.QueryRow(query, teamspeakID).Scan(&user.ID,
+ &user.SteamID, &user.Elo, &user.Admin, &user.Avatar, &user.Name)
if err != nil {
return nil, err
}