Added arena to gql

graph-rework
noah metz 2023-06-08 00:36:16 -06:00
parent 9e2ca6907a
commit fd144eea02
2 changed files with 80 additions and 18 deletions

@ -30,11 +30,61 @@ func GQLVexListAlliance() * graphql.List {
func GQLVexMatchAlliances(p graphql.ResolveParams) (interface{}, error) {
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
//TODO improve
return event.(*Match).alliances, nil
})
}
func GQLVexMatchArena(p graphql.ResolveParams) (interface{}, error) {
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
return event.(*Match).arena, nil
})
}
func GQLVexAllianceTeams(p graphql.ResolveParams) (interface{}, error) {
return GQLResourceFn(p, func(resource Resource, p graphql.ResolveParams) (interface{}, error) {
return resource.(*Alliance).teams, nil
})
}
var gql_vex_type_arena * graphql.Object = nil
func GQLVexTypeArena() * graphql.Object {
if gql_vex_type_arena == nil {
gql_vex_type_arena = graphql.NewObject(graphql.ObjectConfig{
Name: "Arena",
Interfaces: []*graphql.Interface{
GQLInterfaceResource(),
},
IsTypeOf: func(p graphql.IsTypeOfParams) bool {
_, ok := p.Value.(Arena)
return ok
},
Fields: graphql.Fields{},
})
gql_vex_type_arena.AddFieldConfig("ID", &graphql.Field{
Type: graphql.String,
Resolve: GQLResourceID,
})
gql_vex_type_arena.AddFieldConfig("Name", &graphql.Field{
Type: graphql.String,
Resolve: GQLResourceName,
})
gql_vex_type_arena.AddFieldConfig("Description", &graphql.Field{
Type: graphql.String,
Resolve: GQLResourceDescription,
})
gql_vex_type_arena.AddFieldConfig("Parents", &graphql.Field{
Type: GQLListResource(),
Resolve: GQLResourceParents,
})
}
return gql_vex_type_arena
}
var gql_vex_type_match * graphql.Object = nil
func GQLVexTypeMatch() * graphql.Object {
if gql_vex_type_match == nil {
@ -74,6 +124,11 @@ func GQLVexTypeMatch() * graphql.Object {
Type: GQLVexListAlliance(),
Resolve: GQLVexMatchAlliances,
})
gql_vex_type_match.AddFieldConfig("Arena", &graphql.Field{
Type: GQLVexTypeArena(),
Resolve: GQLVexMatchArena,
})
}
return gql_vex_type_match
@ -93,7 +148,6 @@ func GQLVexTypeAlliance() * graphql.Object {
},
Fields: graphql.Fields{},
})
}
gql_vex_type_alliance.AddFieldConfig("ID", &graphql.Field{
Type: graphql.String,
@ -115,6 +169,12 @@ func GQLVexTypeAlliance() * graphql.Object {
Resolve: GQLResourceParents,
})
gql_vex_type_alliance.AddFieldConfig("Teams", &graphql.Field{
Type: GQLVexListTeam(),
Resolve: GQLVexAllianceTeams,
})
}
return gql_vex_type_alliance
}

@ -51,6 +51,7 @@ func NewTeam(org string, team string, members []*Member) * Team {
type Alliance struct {
BaseResource
teams []*Team
}
func NewAlliance(team0 * Team, team1 * Team) * Alliance {
@ -59,6 +60,7 @@ func NewAlliance(team0 * Team, team1 * Team) * Alliance {
resource := &Alliance{
BaseResource: NewBaseResource(name, description, []Resource{team0, team1}),
teams: []*Team{team0, team1},
}
return resource
}