graphql

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const IntrospectionQuery = `` /* 1274-byte string literal not displayed */

Variables

View Source
var (
	ErrQueryingGraphqlEndpoint = errors.New("error querying graphql endpoint")
	ErrGraphqlContainErrors    = errors.New("graphql response contains errors")
	ErrQueryNotAllowed         = errors.New("query not allowed")
)

Functions

func CheckAllowedGraphqlQuery added in v0.0.4

func CheckAllowedGraphqlQuery(
	allowedQueries []string,
	allowedMutations []string,
	queryString string,
) error

func ParseSchema

func ParseSchema(response ResponseIntrospection, filter Filter) string

ParseSchema converts an introspection query result into a GraphQL SDL string.

func Query

func Query[T any](
	ctx context.Context,
	graphqlURL string,
	query string,
	variables map[string]any,
	response *Response[T],
	allowedQueries []string,
	allowedMutations []string,
	requestInterceptor ...func(ctx context.Context, req *http.Request) error,
) error

Types

type EnumValue

type EnumValue struct {
	Name        string  `json:"name"`
	Description *string `json:"description"`
}

EnumValue represents an enum value in a GraphQL schema.

type Errors

type Errors struct {
	Message    string     `json:"message"`
	Extensions Extensions `json:"extensions"`
}

type Extensions

type Extensions struct {
	Path string `json:"path"`
	Code string `json:"code"`
}

type Field

type Field struct {
	Name        string       `json:"name"`
	Description *string      `json:"description"`
	Args        []InputValue `json:"args"`
	Type        Type         `json:"type"`
}

Field represents a field in a GraphQL type.

type Filter

type Filter struct {
	AllowQueries   []Queries
	AllowMutations []Queries
}

type InputValue

type InputValue struct {
	Name         string  `json:"name"`
	Description  *string `json:"description"`
	Type         Type    `json:"type"`
	DefaultValue *string `json:"defaultValue"`
}

InputValue represents an input value in a GraphQL schema.

type IntrospectionResponse

type IntrospectionResponse struct {
	Schema Schema `json:"__schema"`
}

type Kind

type Kind string
const (
	KindObject      Kind = "OBJECT"
	KindNonNull     Kind = "NON_NULL"
	KindList        Kind = "LIST"
	KindScalar      Kind = "SCALAR"
	KindEnum        Kind = "ENUM"
	KindInputObject Kind = "INPUT_OBJECT"
)

func (*Kind) UnmarshalJSON

func (k *Kind) UnmarshalJSON(data []byte) error

type Queries

type Queries struct {
	Name           string
	DisableNesting bool
}

type Response

type Response[T any] struct {
	Data   T        `json:"data"`
	Errors []Errors `json:"errors"`
}

type ResponseIntrospection

type ResponseIntrospection = Response[IntrospectionResponse]

type Schema

type Schema struct {
	QueryType    Type   `json:"queryType"`
	MutationType *Type  `json:"mutationType"`
	Types        []Type `json:"types"`
}

Schema represents the GraphQL schema.

type Type

type Type struct {
	Kind          Kind         `json:"kind"`
	Name          *string      `json:"name"`
	Description   *string      `json:"description"`
	Fields        []Field      `json:"fields"`
	InputFields   []InputValue `json:"inputFields"`
	Interfaces    []Type       `json:"interfaces"`
	EnumValues    []EnumValue  `json:"enumValues"`
	PossibleTypes []Type       `json:"possibleTypes"`
	// For TypeRef fragment
	OfType *Type `json:"ofType"`
}

Type represents a GraphQL type (__Type).

Jump to

Keyboard shortcuts

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