graphql

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Overview

Package graphql offers a param extractor and basic types for building GraphQL requests

Index

Constants

View Source
const (
	// OperationMutation marks an operation as a mutation
	OperationMutation OperationType = "mutation"
	// OperationQuery marks an operation as a query
	OperationQuery OperationType = "query"

	MethodPost OperationMethod = http.MethodPost
	MethodGet  OperationMethod = http.MethodGet
)
View Source
const Namespace = "github.com/devopsfaith/krakend/transport/http/client/graphql"

Namespace is the key for the backend's extra config

Variables

View Source
var ErrNoConfigFound = errors.New("grapghql: no configuration found")

Functions

This section is empty.

Types

type Extractor

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

Extractor exposes two extractor factories: one for the params (query) and one for the request body (mutator)

func New

func New(opt Options) *Extractor

New resturns a new Extractor, ready to be use on a middleware

func (*Extractor) BodyFromBody

func (e *Extractor) BodyFromBody(r io.Reader) ([]byte, error)

BodyFromBody returns a request body containing the graphql request with the given query and the default variables overiden by the request body

func (*Extractor) BodyFromParams

func (e *Extractor) BodyFromParams(params map[string]string) ([]byte, error)

BodyFromParams returns a request body containing the grapql request generated for the given query and the default variables overiden by the request params

func (*Extractor) QueryFromBody

func (e *Extractor) QueryFromBody(r io.Reader) (url.Values, error)

QueryFromBody returns a url.Values containing the graphql request with the given query and the default variables overiden by the request body

func (*Extractor) QueryFromParams

func (e *Extractor) QueryFromParams(params map[string]string) (url.Values, error)

QueryFromParams returns a url.Values containing the grapql request generated for the given query and the default variables overiden by the request params

type GraphQLRequest

type GraphQLRequest struct {
	Query         string                 `json:"query"`
	OperationName string                 `json:"operationName,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty"`
}

GraphQLRequest represents the graphql request body

type OperationMethod

type OperationMethod string

OperationMethod details the method to be used with the request

type OperationType

type OperationType string

OperationType contains all the operations allowed by graphql

type Options

type Options struct {
	GraphQLRequest
	QueryPath string          `json:"query_path,omitempty"`
	Type      OperationType   `json:"type"`
	Method    OperationMethod `json:"method"`
}

Options defines a GraphQLRequest with a type, so the middlewares know what to do

func GetOptions

func GetOptions(cfg config.ExtraConfig) (*Options, error)

GetOptions extracts the Options config from the backend's extra config

Jump to

Keyboard shortcuts

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