2020-08-13 20:14:25 +00:00
|
|
|
package serverapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.jolheiser.com/gql"
|
|
|
|
)
|
|
|
|
|
2020-08-13 20:41:14 +00:00
|
|
|
/**
|
|
|
|
This block of type definitions is primarily for
|
|
|
|
easily creating composite structs for GraphQL queries
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Bans is a list of Ban
|
|
|
|
type Bans []*Ban
|
|
|
|
|
|
|
|
// Players is a list of Player
|
|
|
|
type Players []*Player
|
|
|
|
|
|
|
|
// Plugins is a list of Plugin
|
|
|
|
type Plugins []*Plugin
|
|
|
|
|
|
|
|
// Worlds is a list of World
|
|
|
|
type Worlds []*World
|
|
|
|
|
2020-08-13 20:14:25 +00:00
|
|
|
// GraphQL returns a gql.Client for a ServerAPI instance
|
|
|
|
func (c *Client) GraphQL() *gql.Client {
|
2020-10-06 03:21:20 +00:00
|
|
|
return gql.NewClient(fmt.Sprintf("%s/graphql", c.endpoint), &gql.ClientOptions{
|
|
|
|
HTTP: c.http,
|
2020-08-13 20:14:25 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphQLRequest returns a pre-filled gql.Request with the password set
|
|
|
|
func (c *Client) GraphQLRequest(query string) *gql.Request {
|
|
|
|
req := gql.NewRequest(query)
|
2020-10-06 03:21:20 +00:00
|
|
|
req.Header.Add("X-ServerAPI-Token", c.token)
|
2020-08-13 20:14:25 +00:00
|
|
|
return req
|
|
|
|
}
|