gogql

package module
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 10 Imported by: 0

README

gogql - Go GraphQL things

Copyright (c) 2020, 2024, 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 deprecated

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.

Deprecated: use ProvidedFieldsForCurrentMutation instead.

func ProvidedFieldsForCurrentMutation added in v0.9.4

func ProvidedFieldsForCurrentMutation(ctx context.Context, filterArguments ...string) (map[string][]string, error)

ProvidedFieldsForCurrentMutation retrieves the fields of the Input Object types used as arguments within a gqlgen generated resolver.

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.

This function is intended to be used in gqlgen generated resolvers handling mutations.

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 map[string]any) []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 map[string]any `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"`
}

Jump to

Keyboard shortcuts

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