go-serverapi/graphql.go

39 lines
825 B
Go
Raw Normal View History

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
// GraphQL returns a gql.Client for a ServerAPI instance
func (c *Client) GraphQL() *gql.Client {
return gql.NewClient(fmt.Sprintf("%s/graphql", c.Endpoint), &gql.ClientOptions{
HTTP: c.Options.HTTP,
})
}
// GraphQLRequest returns a pre-filled gql.Request with the password set
func (c *Client) GraphQLRequest(query string) *gql.Request {
req := gql.NewRequest(query)
req.Header.Add("X-ServerAPI-Password", c.Options.Password)
return req
}