graphql

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 15 Imported by: 2

Documentation

Overview

Package graphql provides direct access to the RSC GraphQL API. Can be used to execute both raw queries and prepared low-level queries used by the high-level part of the SDK.

The graphql package tries to stay as close as possible to the GraphQL API:

- Get as a prefix is dropped.

- Names are turned into CamelCase.

- CSP acronyms (e.g. aws) that are part of names are removed.

- Query parameters with values in a well-defined range are turned into types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound signals that the specified entity could not be found.
	ErrNotFound = errors.New("not found")
)

Functions

func QueryName added in v0.1.0

func QueryName(query string) string

QueryName returns the name of the specified GraphQL query.

func RequestError added in v0.10.0

func RequestError(query string, err error) error

RequestError returns a standard formatted error detailing the failure when calling a query/mutation.

func ResponseError added in v0.10.0

func ResponseError(query string, err error) error

ResponseError returns a standard formatted error detailing the error received in response to a query/mutation.

func UnmarshalError added in v0.10.0

func UnmarshalError(query string, err error) error

UnmarshalError returns a standard formatted error detailing the failure to unmarshal the response from a GraphQL query/mutation.

func VersionOlderThan deprecated added in v0.0.17

func VersionOlderThan(version string, versionTags ...string) bool

Deprecated: use Version.Before.

Types

type Client

type Client struct {
	Version string // Deprecated: use DeploymentVersion.
	// contains filtered or unexported fields
}

Client is used to make GraphQL calls to the Polaris platform.

func NewClient added in v0.7.0

func NewClient(apiURL string, tokenSource token.Source) *Client

NewClient returns a new Client for the specified API URL.

func NewClientFromLocalUser deprecated

func NewClientFromLocalUser(app, apiURL, username, password string, logger log.Logger) *Client

Deprecated: use NewClientWithLogger.

func NewClientFromServiceAccount deprecated

func NewClientFromServiceAccount(app, apiURL, accessTokenURI, clientID, clientSecret string, logger log.Logger) *Client

Deprecated: use NewClientWithLogger.

func NewClientWithLogger added in v0.7.0

func NewClientWithLogger(apiURL string, tokenSource token.Source, logger log.Logger) *Client

NewClientWithLogger returns a new Client for the specified API URL, logging to the given logger.

func NewTestClient

func NewTestClient(testServer *httptest.Server) *Client

NewTestClient returns a new Client intended to be used by unit tests.

func NewTestClientWithTokenSource added in v1.1.0

func NewTestClientWithTokenSource(testServer *httptest.Server, tokenSource token.Source) *Client

NewTestClientWithTokenSource returns a new Client with a custom token source intended to be used by unit tests.

func (*Client) DeploymentVersion added in v0.7.0

func (c *Client) DeploymentVersion(ctx context.Context) (Version, error)

DeploymentVersion returns the deployed version of RSC.

func (*Client) Log added in v0.1.0

func (c *Client) Log() log.Logger

Log returns the logger.

func (*Client) Request

func (c *Client) Request(ctx context.Context, query string, variables any) ([]byte, error)

Request posts the specified GraphQL query/mutation with the given variables to the Polaris platform. Returns the response JSON text as is. If the request fails due to temporary error, it will be retried automatically.

func (*Client) RequestWithoutLogging added in v0.10.0

func (c *Client) RequestWithoutLogging(ctx context.Context, query string, variables interface{}) ([]byte, error)

RequestWithoutLogging posts the specified GraphQL query/mutation with the given variables to the Polaris platform. Returns the response JSON text as is. The variables are not logged before the request is made. Certain temporary errors will be retried.

func (*Client) RequestWithoutRetry added in v0.9.1

func (c *Client) RequestWithoutRetry(ctx context.Context, query string, variables interface{}) ([]byte, error)

RequestWithoutRetry posts the specified GraphQL query/mutation with the given variables to the Polaris platform. Returns the response JSON text as is.

func (*Client) SetLogger added in v0.7.0

func (c *Client) SetLogger(logger log.Logger)

SetLogger sets the logger to use.

type GQLError added in v0.6.0

type GQLError struct {
	Data   interface{} `json:"data"`
	Errors []struct {
		Message   string        `json:"message"`
		Path      []interface{} `json:"path"`
		Locations []struct {
			Line   int `json:"line"`
			Column int `json:"column"`
		} `json:"locations"`
		Extensions struct {
			Code  int `json:"code"`
			Trace struct {
				Operation string `json:"operation"`
				TraceID   string `json:"traceId"`
				SpanID    string `json:"spanId"`
			} `json:"trace"`
		} `json:"extensions"`
	} `json:"errors"`
}

GQLError is returned by RSC in the body of a response as a JSON document when certain types of GraphQL errors occur.

func (GQLError) Code added in v1.1.0

func (e GQLError) Code() int

Code returns the status code of the first error with a non-zero extension status code. If no error has a non-zero status code, 0 is returned.

func (GQLError) Error added in v0.6.0

func (e GQLError) Error() string

type Version added in v0.7.0

type Version string

Version represents an RSC version, e.g. latest, master-54647 or v20230227-3.

func (Version) Before added in v0.7.0

func (v Version) Before(versionTags ...string) bool

Before returns true if the version is older than, lexicographically before, version tags of the same version format. Note that "latest" is never older than any version tag.

Directories

Path Synopsis
Package access provides a low level interface to the users, groups and roles management GraphQL queries provided by the RSC platform.
Package access provides a low level interface to the users, groups and roles management GraphQL queries provided by the RSC platform.
Package aws provides a low-level interface to the AWS GraphQL queries provided by the Polaris platform.
Package aws provides a low-level interface to the AWS GraphQL queries provided by the Polaris platform.
Package azure provides a low-level interface to the Azure GraphQL queries provided by the Polaris platform.
Package azure provides a low-level interface to the Azure GraphQL queries provided by the Polaris platform.
Package core provides a low-level interface to core GraphQL queries provided by the Polaris platform.
Package core provides a low-level interface to core GraphQL queries provided by the Polaris platform.
Package gcp provides a low level interface to the GCP GraphQL queries provided by the RSC platform.
Package gcp provides a low level interface to the GCP GraphQL queries provided by the RSC platform.

Jump to

Keyboard shortcuts

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