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) { func GQLVexMatchAlliances(p graphql.ResolveParams) (interface{}, error) {
return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) { return GQLEventFn(p, func(event Event, p graphql.ResolveParams) (interface{}, error) {
//TODO improve
return event.(*Match).alliances, nil 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 var gql_vex_type_match * graphql.Object = nil
func GQLVexTypeMatch() * graphql.Object { func GQLVexTypeMatch() * graphql.Object {
if gql_vex_type_match == nil { if gql_vex_type_match == nil {
@ -74,6 +124,11 @@ func GQLVexTypeMatch() * graphql.Object {
Type: GQLVexListAlliance(), Type: GQLVexListAlliance(),
Resolve: GQLVexMatchAlliances, Resolve: GQLVexMatchAlliances,
}) })
gql_vex_type_match.AddFieldConfig("Arena", &graphql.Field{
Type: GQLVexTypeArena(),
Resolve: GQLVexMatchArena,
})
} }
return gql_vex_type_match return gql_vex_type_match
@ -93,27 +148,32 @@ func GQLVexTypeAlliance() * graphql.Object {
}, },
Fields: graphql.Fields{}, Fields: graphql.Fields{},
}) })
}
gql_vex_type_alliance.AddFieldConfig("ID", &graphql.Field{ gql_vex_type_alliance.AddFieldConfig("ID", &graphql.Field{
Type: graphql.String, Type: graphql.String,
Resolve: GQLResourceID, Resolve: GQLResourceID,
}) })
gql_vex_type_alliance.AddFieldConfig("Name", &graphql.Field{ gql_vex_type_alliance.AddFieldConfig("Name", &graphql.Field{
Type: graphql.String, Type: graphql.String,
Resolve: GQLResourceName, Resolve: GQLResourceName,
}) })
gql_vex_type_alliance.AddFieldConfig("Description", &graphql.Field{ gql_vex_type_alliance.AddFieldConfig("Description", &graphql.Field{
Type: graphql.String, Type: graphql.String,
Resolve: GQLResourceDescription, Resolve: GQLResourceDescription,
}) })
gql_vex_type_alliance.AddFieldConfig("Parents", &graphql.Field{ gql_vex_type_alliance.AddFieldConfig("Parents", &graphql.Field{
Type: GQLListResource(), Type: GQLListResource(),
Resolve: GQLResourceParents, Resolve: GQLResourceParents,
}) })
gql_vex_type_alliance.AddFieldConfig("Teams", &graphql.Field{
Type: GQLVexListTeam(),
Resolve: GQLVexAllianceTeams,
})
}
return gql_vex_type_alliance return gql_vex_type_alliance
} }

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