gogql

package module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 10 Imported by: 0

README

gogql - Go GraphQL things

Copyright (c) 2020, 2023, Geert JM Vanderkelen

The gogql package contains various tooling around GraphQL.

License

Distributed under the MIT license. See LICENSE.md for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GQLGenInputObjectFields

func GQLGenInputObjectFields(ctx context.Context, arguments ...string) (map[string][]string, error)

GQLGenInputObjectFields retrieves the fields of the Input Object types used as arguments when executing mutations. For example, `mutation { updateUser(input: {id: 123, name: "Marta"}) { id }` would return the fields "id" and "name" returning a map with key 'input', and slice of strings. If no arguments are specified, 'input' will be returned (if available). This also works when variables are used. Nil is returned when no operation is in context, or when the operation is not a mutation, or no arguments were available.

Types

type Client

type Client struct {
	ContentType string
	HttpClient  *http.Client
	// contains filtered or unexported fields
}

Client defines a GraphQL client connecting to the endpoint using HTTP.

func NewClient

func NewClient(apiEndpoint string) *Client

NewClient returns a new GraphQL Client connecting to the apiEndpoint.

func (*Client) Execute

func (c *Client) Execute(query string, result any) []error

Execute executes the GraphQL query.

func (*Client) ExecuteWithVars

func (c *Client) ExecuteWithVars(query string, result interface{}, vars Variables) []error

func (*Client) SetHeader added in v0.9.2

func (c *Client) SetHeader(key, value string)

type Payload

type Payload struct {
	Query     string    `json:"query"`
	Variables Variables `json:"variables,omitempty"`
}

Payload defines what we send to the GraphQL endpoint.

type Result

type Result struct {
	Data   json.RawMessage  `json:"data,omitempty"`
	Errors []gqlerror.Error `json:"errors,omitempty"`
}

type Variables

type Variables map[string]any

Variables defines a key/value mapping which can be used to pass variables when executing GraphQL queries.

Jump to

Keyboard shortcuts

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