gqlmock

package
v0.0.0-...-2263012 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MockEndpoint string = "/graphql"

Variables

This section is empty.

Functions

func MustMarshalJSON

func MustMarshalJSON(v map[string]interface{}) []byte

func MustUnmarshalJSON

func MustUnmarshalJSON(data []byte, v any)

func MustWrite

func MustWrite(w io.Writer, s string)

func MuxWithFuncResponseArray

func MuxWithFuncResponseArray(responses []ResponseFunc) *http.ServeMux

func MuxWithJSONResponse

func MuxWithJSONResponse(response map[string]interface{}) *http.ServeMux

func MuxWithJSONResponseArray

func MuxWithJSONResponseArray(responses []interface{}) *http.ServeMux

func MuxWithJSONResponseMap

func MuxWithJSONResponseMap(responses map[string]interface{}) *http.ServeMux

func NewClient

func NewClient(mux *http.ServeMux) graphql.Client

func NewClientWithFuncResponseArray

func NewClientWithFuncResponseArray(responses []ResponseFunc) graphql.Client

NewClientWithFuncResponseArray creates a GQL client that will respond with a series of results of handler functions

func NewClientWithJSONResponseArray

func NewClientWithJSONResponseArray(responses []interface{}) graphql.Client

Takes an array of responses and creates a graphql client that returns them in order

func NewClientWithJSONResponseMap

func NewClientWithJSONResponseMap(responses map[string]interface{}) graphql.Client

Takes a map of graphql operation names to JSON responses and creates a GraphQL client that returns based on operation name

func NewClientWithSingleJSONResponse

func NewClientWithSingleJSONResponse(response map[string]interface{}) graphql.Client

Takes a JSON map and creates a GraphQL client that always returns it

func ParseInputVariables

func ParseInputVariables(req *http.Request) map[string]interface{}

ParseInputVariables parses graphql input variables from request and returns a JSON-ish map

Types

type GraphQLRequest

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

type MutationResponse

type MutationResponse struct {
	Data map[string]MutationResponseData `json:"data"`
}

func MockMutationResponse

func MockMutationResponse(operationName string, result interface{}) MutationResponse

MockMutationResponse creates a successful mutation response from a mutation name and payload

type MutationResponseData

type MutationResponseData struct {
	Successful bool                      `json:"successful"`
	Result     interface{}               `json:"result"`
	Messages   []MutationResponseMessage `json:"messages"`
}

type MutationResponseMessage

type MutationResponseMessage struct {
	Message string `json:"message"`
}

type QueryResponse

type QueryResponse struct {
	Data map[string]interface{} `json:"data"`
}

func MockQueryResponse

func MockQueryResponse(operationName string, responseData interface{}) QueryResponse

type ResponseFunc

type ResponseFunc func(req *http.Request) interface{}

Jump to

Keyboard shortcuts

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