diff --git a/gql_vex.go b/gql_vex.go index a2d7a16..aeb0e93 100644 --- a/gql_vex.go +++ b/gql_vex.go @@ -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,27 +148,32 @@ func GQLVexTypeAlliance() * graphql.Object { }, Fields: graphql.Fields{}, }) - } - gql_vex_type_alliance.AddFieldConfig("ID", &graphql.Field{ - Type: graphql.String, - Resolve: GQLResourceID, - }) + gql_vex_type_alliance.AddFieldConfig("ID", &graphql.Field{ + Type: graphql.String, + Resolve: GQLResourceID, + }) - gql_vex_type_alliance.AddFieldConfig("Name", &graphql.Field{ - Type: graphql.String, - Resolve: GQLResourceName, - }) + gql_vex_type_alliance.AddFieldConfig("Name", &graphql.Field{ + Type: graphql.String, + Resolve: GQLResourceName, + }) - gql_vex_type_alliance.AddFieldConfig("Description", &graphql.Field{ - Type: graphql.String, - Resolve: GQLResourceDescription, - }) + gql_vex_type_alliance.AddFieldConfig("Description", &graphql.Field{ + Type: graphql.String, + Resolve: GQLResourceDescription, + }) - gql_vex_type_alliance.AddFieldConfig("Parents", &graphql.Field{ - Type: GQLListResource(), - Resolve: GQLResourceParents, - }) + gql_vex_type_alliance.AddFieldConfig("Parents", &graphql.Field{ + Type: GQLListResource(), + Resolve: GQLResourceParents, + }) + + gql_vex_type_alliance.AddFieldConfig("Teams", &graphql.Field{ + Type: GQLVexListTeam(), + Resolve: GQLVexAllianceTeams, + }) + } return gql_vex_type_alliance } diff --git a/vex.go b/vex.go index 22d0a3b..2ad1f88 100644 --- a/vex.go +++ b/vex.go @@ -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 }