gqlclient

package
v0.0.0-...-6c4fd92 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: NIST-PD-fallback Imports: 13 Imported by: 0

Documentation

Overview

Package gqlclient provides a GraphQL client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeListenAddress

func MakeListenAddress(uri string) (hostport string, e error)

MakeListenAddress constructs server listen string.

Types

type Client

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

Client is a GraphQL client.

func New

func New(cfg Config) (*Client, error)

New creates a Client.

func (*Client) Close

func (c *Client) Close() error

Close blocks until all pending operations have concluded.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, id string) (deleted bool, e error)

Delete runs the delete mutation.

func (*Client) Do

func (c *Client) Do(ctx context.Context, query string, vars map[string]any, key string, res any) error

Do runs a query or mutation on the GraphQL server.

ctx: a Context for canceling the operation.
query: a GraphQL document.
vars: query variables.
key: if non-empty, unmarshal result.data[key] instead of result.data.
res: pointer to result struct.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, query string, vars map[string]any, key string, res any) error

Subscribe performs a subscription on the GraphQL server.

ctx: a Context for canceling the subscription.
query: a GraphQL document.
vars: query variables.
key: if non-empty, unmarshal result.data[key] instead of result.data.
res: channel for sending updates.

type Config

type Config struct {
	// HTTPUri is HTTP URI for query and mutation operations.
	HTTPUri string

	HTTPClient *http.Client

	// WebSocketUri is WebSocket URI for subscription operations.
	// Default is same as HTTPURI except changing the scheme.
	WebSocketUri string

	WebSocketDialer *gqlws.Dialer
}

Config contains Client configuration.

func (Config) Listen

func (cfg Config) Listen() (hostport string, e error)

Listen constructs server listen string.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate applies defaults and validates the configuration.

Jump to

Keyboard shortcuts

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