graphql

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddVarNamesToQuery

func AddVarNamesToQuery(query string, varNames ...interface{}) string

AddVarNamesToQuery accepts a query or mutation definition and will populate the definition with the variables passed. The definitions use the notation: $%[1]s, $%[2]s, etc... to avoid passing the same variables multiple times in the varNames field(s). When wanting to reference a variable several times inside a format string, the variables can be reference by position using %[n] where n is the index of the parameter (1 based).

func ExecuteQuery

func ExecuteQuery(cli HTTPClient, serverURL string, graphqlReq *Request, out interface{}) error

ExecuteQuery is shorthand for ExecuteQueryContext with the given args. Look to ExecuteQueryContext for more details.

func ExecuteQueryContext

func ExecuteQueryContext(ctx context.Context, qc *QueryConfig) error

ExecuteQueryContext takes a context for HTTP request control and the given QueryConfig. It executes the graphql request against the proveded HTTPClient, returning an error or unmarshalling into QueryConfig.Output if provided. HClient, ServerURL, and Request are required in QueryConfig.

func ExecuteQueryContextWithTenant

func ExecuteQueryContextWithTenant(ctx context.Context, qc *QueryConfig) (string, error)

func ExecuteQueryEscapeHTML

func ExecuteQueryEscapeHTML(cli HTTPClient, serverURL string, graphqlReq *Request, escapeHTML bool, out interface{}) error

ExecuteQueryEscapeHTML is shorthand for ExecuteQueryContext with the given args. Look to ExecuteQueryContext for more details.

func ExecuteQueryWithTenant

func ExecuteQueryWithTenant(cli HTTPClient, serverURL string, graphqlReq *Request, out interface{}) (string, error)

func NewMockSubServer

func NewMockSubServer(t *testing.T, expectedQuery string, expectedVars map[string]interface{}, outputs ...interface{}) *httptest.Server

func SubscriptionSendKAMessages

func SubscriptionSendKAMessages(s *Subscription)

Types

type Error

type Error struct {
	Message   string           `json:"message"`
	Locations []map[string]int `json:"locations"`
	Path      []string         `json:"path"`
}

Error is the response type for graphql errors from our gateway

func (Error) Error

func (e Error) Error() string

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
	Header() http.Header
}

HTTPClient is any client that can perform HTTP requests. It is often but not always github.com/secureworks/taegis-sdk-go/client

type KeepAliveMessage

type KeepAliveMessage struct{}

type Message

type Message struct {
	Payload interface{}
	Err     error
}

type QueryConfig

type QueryConfig struct {
	ServerURL  string
	HClient    HTTPClient
	Request    *Request
	Header     http.Header //DEPRECATED - DO NOT USE. Use graphql.RequestOptions instead
	EscapeHTML bool
	LimitRead  int64
	Output     interface{}
	// contains filtered or unexported fields
}

QueryConfig takes all necessary or optional params for this package's Execute functions.

type Request

type Request struct {
	Query     string                 `json:"query"`
	Variables map[string]interface{} `json:"variables"`
	Header    http.Header
	// contains filtered or unexported fields
}

Request is the standard graphql request format to send to an API This should NOT be instantiated directly, you should use the NewRequest method to make sure your getting everything you need set

func NewRequest

func NewRequest(query string, opts ...RequestOption) *Request

NewRequest creates a default graphql request with empty vars The Request struct should NOT be created directly - it should use this method so we can make sure everything is set on your graphql request

func (*Request) Var

func (r *Request) Var(key string, value interface{})

Var lets you set variables for input in a graphql request

func (*Request) Vars

func (r *Request) Vars(vars map[string]interface{})

Vars lets you add multiple values at once if you know them ahead of time

type RequestOption

type RequestOption func(r *Request)

RequestOption are for the services to use to provide a token *per* request instead of one for the overall client

func RequestWithHeader

func RequestWithHeader(header http.Header) RequestOption

RequestWithHeader adds a set of headers to the request, any headers that are already present, will be skipped

func RequestWithLogger

func RequestWithLogger(logger log.Logger) RequestOption

RequestWithLogger adds a logger for possibly more verbose output

func RequestWithTenant

func RequestWithTenant(tenantID string) RequestOption

RequestWithTenant adds a tenant id to the individual request, overriding one set by client.Options

func RequestWithToken

func RequestWithToken(token string) RequestOption

RequestWithToken adds a bearer token to the individual request, overriding one set by client.Options

type Response

type Response struct {
	Data  interface{} `json:"data"`
	Error []Error     `json:"errors"`
}

type ResponseFields

type ResponseFields string

ResponseFields is used to define what graphql response fields we want back from the server

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

func NewSubscription

func NewSubscription(ctx context.Context, u *url.URL, query string, responseCreator func() interface{}, opts ...SubscriptionOption) (*Subscription, error)

func (*Subscription) Messages

func (s *Subscription) Messages() <-chan *Message

func (*Subscription) Shutdown

func (s *Subscription) Shutdown(ctx context.Context) error

type SubscriptionOption

type SubscriptionOption func(s *Subscription)

func SubscriptionWithHeader

func SubscriptionWithHeader(header http.Header) SubscriptionOption

func SubscriptionWithLog

func SubscriptionWithLog(l log.Logger) SubscriptionOption

func SubscriptionWithTenant

func SubscriptionWithTenant(tenantID string) SubscriptionOption

func SubscriptionWithToken

func SubscriptionWithToken(token string) SubscriptionOption

func SubscriptionWithVars

func SubscriptionWithVars(vars map[string]interface{}) SubscriptionOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL