graphql

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 27 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyRequest = errors.New("the provided request is empty")
	ErrNilSchema    = errors.New("the provided schema is nil")
)
View Source
var CountriesSchema = `` /* 1558-byte string literal not displayed */
View Source
var DefaultComplexityCalculator = defaultComplexityCalculator{}

Functions

func LoadStarWarsQuery

func LoadStarWarsQuery(starwarsFile string, variables starwars.QueryVariables) func(t *testing.T) Request

func UnmarshalHttpRequest

func UnmarshalHttpRequest(r *http.Request, request *Request) error

func UnmarshalRequest

func UnmarshalRequest(reader io.Reader, request *Request) error

Types

type ComplexityCalculator

type ComplexityCalculator interface {
	Calculate(operation, definition *ast.Document) (ComplexityResult, error)
}

type ComplexityResult

type ComplexityResult struct {
	NodeCount    int
	Complexity   int
	Depth        int
	PerRootField []FieldComplexityResult
	Errors       graphqlerrors.Errors
}

type DefaultFieldsValidator

type DefaultFieldsValidator struct {
}

func (DefaultFieldsValidator) Validate deprecated

func (d DefaultFieldsValidator) Validate(request *Request, schema *Schema, restrictions []Type) (RequestFieldsValidationResult, error)

Validate validates a request by checking if `restrictions` contains blocked fields.

Deprecated: This function can only handle blocked fields. Use `ValidateByFieldList` if you want to check for blocked or allowed fields instead.

func (DefaultFieldsValidator) ValidateByFieldList

func (d DefaultFieldsValidator) ValidateByFieldList(request *Request, schema *Schema, restrictionList FieldRestrictionList) (RequestFieldsValidationResult, error)

ValidateByFieldList will validate a request by using a list of allowed or blocked fields.

type EngineResultWriter

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

func NewEngineResultWriter

func NewEngineResultWriter() EngineResultWriter

func NewEngineResultWriterFromBuffer

func NewEngineResultWriterFromBuffer(buf *bytes.Buffer) EngineResultWriter

func (*EngineResultWriter) AsHTTPResponse

func (e *EngineResultWriter) AsHTTPResponse(status int, headers http.Header) *http.Response

func (*EngineResultWriter) Bytes

func (e *EngineResultWriter) Bytes() []byte

func (*EngineResultWriter) Complete

func (e *EngineResultWriter) Complete()

func (*EngineResultWriter) Flush

func (e *EngineResultWriter) Flush() error

func (*EngineResultWriter) Len

func (e *EngineResultWriter) Len() int

func (*EngineResultWriter) Read

func (e *EngineResultWriter) Read(p []byte) (n int, err error)

func (*EngineResultWriter) Reset

func (e *EngineResultWriter) Reset()

func (*EngineResultWriter) SetFlushCallback

func (e *EngineResultWriter) SetFlushCallback(flushCb func(data []byte))

func (*EngineResultWriter) String

func (e *EngineResultWriter) String() string

func (*EngineResultWriter) Write

func (e *EngineResultWriter) Write(p []byte) (n int, err error)

type Extractor

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

func NewExtractor

func NewExtractor() *Extractor

func (*Extractor) ExtractFieldsFromRequest

func (e *Extractor) ExtractFieldsFromRequest(request *Request, schema *Schema, report *operationreport.Report, data RequestTypes)

type FieldComplexityResult

type FieldComplexityResult struct {
	TypeName   string
	FieldName  string
	Alias      string
	NodeCount  int
	Complexity int
	Depth      int
}

type FieldRestrictionList

type FieldRestrictionList struct {
	Kind  FieldRestrictionListKind
	Types []Type
}

type FieldRestrictionListKind

type FieldRestrictionListKind int
const (
	AllowList FieldRestrictionListKind = iota
	BlockList
)

type FieldRestrictionValidator

type FieldRestrictionValidator interface {
	ValidateByFieldList(request *Request, schema *Schema, restrictionList FieldRestrictionList) (RequestFieldsValidationResult, error)
}

type NormalizationResult

type NormalizationResult struct {
	Successful bool
	Errors     graphqlerrors.Errors
}

func NormalizationResultFromReport

func NormalizationResultFromReport(report operationreport.Report) (NormalizationResult, error)

type OperationType

type OperationType ast.OperationType

type Request

type Request struct {
	OperationName string          `json:"operationName"`
	Variables     json.RawMessage `json:"variables,omitempty"`
	Query         string          `json:"query"`
	// contains filtered or unexported fields
}

func StarwarsRequestForQuery

func StarwarsRequestForQuery(t TestingTB, fileName string) Request

func (*Request) CalculateComplexity

func (r *Request) CalculateComplexity(complexityCalculator ComplexityCalculator, schema *Schema) (ComplexityResult, error)

func (*Request) Document

func (r *Request) Document() *ast.Document

func (*Request) InternalRequest

func (r *Request) InternalRequest() resolve.Request

func (*Request) IsIntrospectionQuery

func (r *Request) IsIntrospectionQuery() (result bool, err error)

func (*Request) IsNormalized

func (r *Request) IsNormalized() bool

func (*Request) Normalize

func (r *Request) Normalize(schema *Schema) (result NormalizationResult, err error)

func (*Request) OperationType

func (r *Request) OperationType() (OperationType, error)

func (*Request) Print

func (r *Request) Print(writer io.Writer) (n int, err error)

func (*Request) SetHeader

func (r *Request) SetHeader(header http.Header)

func (*Request) ValidateFieldRestrictions

func (r *Request) ValidateFieldRestrictions(schema *Schema, restrictedFieldsList FieldRestrictionList, validator FieldRestrictionValidator) (RequestFieldsValidationResult, error)

ValidateFieldRestrictions will validate a request by using a list of allowed or blocked fields.

func (*Request) ValidateForSchema

func (r *Request) ValidateForSchema(schema *Schema) (result ValidationResult, err error)

func (*Request) ValidateRestrictedFields deprecated

func (r *Request) ValidateRestrictedFields(schema *Schema, restrictedFields []Type) (RequestFieldsValidationResult, error)

ValidateRestrictedFields validates a request by checking if `restrictedFields` contains blocked fields.

Deprecated: This function can only handle blocked fields. Use `ValidateFieldRestrictions` if you want to check for blocked or allowed fields instead.

type RequestFields

type RequestFields map[string]struct{}

type RequestFieldsValidationResult

type RequestFieldsValidationResult struct {
	Valid  bool
	Errors graphqlerrors.Errors
}

type RequestFieldsValidator

type RequestFieldsValidator interface {
	Validate(request *Request, schema *Schema, restrictions []Type) (RequestFieldsValidationResult, error)
}

type RequestTypes

type RequestTypes map[string]RequestFields

type Schema

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

func CreateCountriesSchema

func CreateCountriesSchema(t *testing.T) *Schema

func InputCoercionForListSchema

func InputCoercionForListSchema(t *testing.T) *Schema

func NewSchemaFromReader

func NewSchemaFromReader(reader io.Reader) (*Schema, error)

func NewSchemaFromString

func NewSchemaFromString(schema string) (*Schema, error)

func StarwarsSchema

func StarwarsSchema(t TestingTB) *Schema

func (*Schema) Document

func (s *Schema) Document() *ast.Document

func (*Schema) GetAllFieldArguments

func (s *Schema) GetAllFieldArguments(skipFieldFuncs ...SkipFieldFunc) []TypeFieldArguments

func (*Schema) GetAllNestedFieldChildrenFromTypeField

func (s *Schema) GetAllNestedFieldChildrenFromTypeField(typeName string, fieldName string, skipFieldFuncs ...SkipFieldFunc) []TypeFields

func (*Schema) HasMutationType

func (s *Schema) HasMutationType() bool

func (*Schema) HasQueryType

func (s *Schema) HasQueryType() bool

HasQueryType TODO: should be deprecated?

func (*Schema) HasSubscriptionType

func (s *Schema) HasSubscriptionType() bool

func (*Schema) Hash

func (s *Schema) Hash() uint64

Hash returns the hash of the schema.

func (*Schema) Input

func (s *Schema) Input() []byte

func (*Schema) IsNormalized

func (s *Schema) IsNormalized() bool

func (*Schema) MutationTypeName

func (s *Schema) MutationTypeName() string

func (*Schema) Normalize

func (s *Schema) Normalize() (result NormalizationResult, err error)

func (*Schema) QueryTypeName

func (s *Schema) QueryTypeName() string

func (*Schema) RawSchema

func (s *Schema) RawSchema() []byte

func (*Schema) SubscriptionTypeName

func (s *Schema) SubscriptionTypeName() string

func (*Schema) Validate

func (s *Schema) Validate() (result ValidationResult, err error)

type SchemaValidationError

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

func (SchemaValidationError) Error

func (s SchemaValidationError) Error() string

type SchemaValidationErrors

type SchemaValidationErrors []SchemaValidationError

func (SchemaValidationErrors) Count

func (s SchemaValidationErrors) Count() int

func (SchemaValidationErrors) Error

func (s SchemaValidationErrors) Error() string

func (SchemaValidationErrors) ErrorByIndex

func (s SchemaValidationErrors) ErrorByIndex(i int) error

func (SchemaValidationErrors) WriteResponse

func (s SchemaValidationErrors) WriteResponse(writer io.Writer) (n int, err error)

type SkipFieldFunc

type SkipFieldFunc func(typeName, fieldName string, definition ast.Document) bool

func NewIsDataSourceConfigV2RootFieldSkipFunc

func NewIsDataSourceConfigV2RootFieldSkipFunc(dataSources []plan.DataSource) SkipFieldFunc

func NewSkipReservedNamesFunc

func NewSkipReservedNamesFunc() SkipFieldFunc

type TestingTB

type TestingTB interface {
	Errorf(format string, args ...interface{})
	Helper()
	FailNow()
}

type Type

type Type struct {
	Name   string   `json:"name"`
	Fields []string `json:"fields"`
}

type TypeFieldArguments

type TypeFieldArguments struct {
	TypeName      string
	FieldName     string
	ArgumentNames []string
}

type TypeFields

type TypeFields struct {
	TypeName   string
	FieldNames []string
}

type ValidationResult

type ValidationResult struct {
	Valid  bool
	Errors graphqlerrors.Errors
}

func ValidateSchemaString

func ValidateSchemaString(schema string) (result ValidationResult, err error)

Jump to

Keyboard shortcuts

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