github.com/TykTechnologies/tyk/internal/graphql
Package graphql is a generated GoMock package.
Package
Files: 4. Third party imports: 2. Imports from organisation: 9. Tests: 0. Benchmarks: 0.
Vars
var _ TykOtelExecutorI = (*OtelGraphqlEngineV2Basic)(nil)
Types
ExecutionEngineI
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type ExecutionEngineI interface {
graphql.CustomExecutionEngineV2
graphql.ExecutionEngineV2Executor
}
GraphStatsExtractionVisitor
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| extractor |
|
No comment on field. |
| gqlRequest |
|
No comment on field. |
| schema |
|
No comment on field. |
type GraphStatsExtractionVisitor struct {
extractor *graphql.Extractor
gqlRequest *graphql.Request
schema *ast.Document
}
MockExecutionEngineI
MockExecutionEngineI is a mock of ExecutionEngineI interface.
| Field name | Field type | Comment |
|---|---|---|
| ctrl |
|
No comment on field. |
| recorder |
|
No comment on field. |
type MockExecutionEngineI struct {
ctrl *gomock.Controller
recorder *MockExecutionEngineIMockRecorder
}
MockExecutionEngineIMockRecorder
MockExecutionEngineIMockRecorder is the mock recorder for MockExecutionEngineI.
| Field name | Field type | Comment |
|---|---|---|
| mock |
|
No comment on field. |
type MockExecutionEngineIMockRecorder struct {
mock *MockExecutionEngineI
}
OtelGraphqlEngineV2Basic
OtelGraphqlEngineV2Basic defines a struct that can be used for basic tracing with OTel. All execution stages are squashed into one span: GraphqlEngine. The upstream request still has its span and GraphqlEngine is its parent span.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. |
type OtelGraphqlEngineV2Basic struct {
otelGraphqlEngineV2Common
}
OtelGraphqlEngineV2Detailed
OtelGraphqlEngineV2Detailed defines an execution engine that can be used for detailed tracing with OTel.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. | |
| schema |
|
No comment on field. |
type OtelGraphqlEngineV2Detailed struct {
otelGraphqlEngineV2Common
schema *graphql.Schema
}
TykOtelExecutorI
TykOtelExecutorI is an interface that inherits ExecutionEngineI and defines Tyk/UDG specific methods.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type TykOtelExecutorI interface {
ExecutionEngineI
// SetContext sets the current OTel tracer context.
SetContext(ctx context.Context)
}
otelGraphqlEngineV2Common
otelGraphqlEngineV2Common is a struct that implements the common/default methods of TykOtelExecutorI interface.
| Field name | Field type | Comment |
|---|---|---|
| mutex |
|
No comment on field. |
| traceContext |
|
No comment on field. |
| tracerProvider |
|
No comment on field. |
| engine |
|
No comment on field. |
| executor |
|
No comment on field. |
type otelGraphqlEngineV2Common struct {
mutex sync.Mutex
traceContext context.Context
tracerProvider otel.TracerProvider
engine ExecutionEngineI
executor graphql.ExecutionEngineV2Executor
}
Functions
func NewGraphStatsExtractor
func NewGraphStatsExtractor() *GraphStatsExtractionVisitor {
extractor := &GraphStatsExtractionVisitor{
extractor: graphql.NewExtractor(),
}
return extractor
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func NewMockExecutionEngineI
NewMockExecutionEngineI creates a new mock instance.
func NewMockExecutionEngineI(ctrl *gomock.Controller) *MockExecutionEngineI {
mock := &MockExecutionEngineI{ctrl: ctrl}
mock.recorder = &MockExecutionEngineIMockRecorder{mock}
return mock
}
Cognitive complexity: 2, Cyclomatic complexity: 1
func NewOtelGraphqlEngineV2Basic
func NewOtelGraphqlEngineV2Basic(tracerProvider otel.TracerProvider, engine ExecutionEngineI) (*OtelGraphqlEngineV2Basic, error) {
otelEngine := &OtelGraphqlEngineV2Basic{
otelGraphqlEngineV2Common{
tracerProvider: tracerProvider,
engine: engine,
},
}
executor, err := graphql.NewCustomExecutionEngineV2Executor(otelEngine)
if err != nil {
return nil, err
}
otelEngine.executor = executor
return otelEngine, nil
}
Cognitive complexity: 4, Cyclomatic complexity: 2
func NewOtelGraphqlEngineV2Detailed
NewOtelGraphqlEngineV2Detailed creates a new instance of OtelGraphqlEngineV2Detailed. It takes a tracer provider, an execution engine, and a GraphQL schema as parameters. The function returns a pointer to OtelGraphqlEngineV2Detailed and an error if any.
/*
NewOtelGraphqlEngineV2Detailed creates a new instance of OtelGraphqlEngineV2Detailed.
It takes a tracer provider, an execution engine, and a GraphQL schema as parameters.
The function returns a pointer to OtelGraphqlEngineV2Detailed and an error if any.
*/
func NewOtelGraphqlEngineV2Detailed(tracerProvider otel.TracerProvider, engine ExecutionEngineI, schema *graphql.Schema) (*OtelGraphqlEngineV2Detailed, error) {
otelEngine := &OtelGraphqlEngineV2Detailed{
otelGraphqlEngineV2Common: otelGraphqlEngineV2Common{
tracerProvider: tracerProvider,
engine: engine,
},
schema: schema,
}
executor, err := graphql.NewCustomExecutionEngineV2Executor(otelEngine)
if err != nil {
return nil, err
}
otelEngine.executor = executor
return otelEngine, nil
}
Cognitive complexity: 4, Cyclomatic complexity: 2
func PrintOperationType
func PrintOperationType(operationType ast.OperationType) string {
switch operationType {
case ast.OperationTypeQuery:
return string(literal.QUERY)
case ast.OperationTypeMutation:
return string(literal.MUTATION)
case ast.OperationTypeSubscription:
return string(literal.SUBSCRIPTION)
case ast.OperationTypeUnknown:
return "unknown"
default:
return "unknown"
}
}
Cognitive complexity: 6, Cyclomatic complexity: 6
func (*GraphStatsExtractionVisitor) AnalyticsOperationTypes
func (g *GraphStatsExtractionVisitor) AnalyticsOperationTypes() analytics.GraphQLOperations {
if g.gqlRequest == nil {
return analytics.OperationUnknown
}
op, _ := g.gqlRequest.OperationType()
switch op {
case graphql.OperationTypeQuery:
return analytics.OperationQuery
case graphql.OperationTypeMutation:
return analytics.OperationMutation
case graphql.OperationTypeSubscription:
return analytics.OperationSubscription
default:
return analytics.OperationUnknown
}
}
Cognitive complexity: 7, Cyclomatic complexity: 6
func (*GraphStatsExtractionVisitor) ExtractStats
func (g *GraphStatsExtractionVisitor) ExtractStats(rawRequest, response, schema string) (analytics.GraphQLStats, error) {
var stats analytics.GraphQLStats
stats.IsGraphQL = true
var gqlRequest graphql.Request
if err := graphql.UnmarshalRequest(strings.NewReader(rawRequest), &gqlRequest); err != nil {
return stats, err
}
g.gqlRequest = &gqlRequest
stats.Variables = string(g.gqlRequest.Variables)
sh, err := graphql.NewSchemaFromString(schema)
if err != nil {
return stats, err
}
schemaDoc, opReport := astparser.ParseGraphqlDocumentBytes(sh.Document())
if opReport.HasErrors() {
return stats, opReport
}
g.schema = &schemaDoc
requestTypes := make(graphql.RequestTypes)
var report operationreport.Report
g.extractor.ExtractFieldsFromRequestSingleOperation(g.gqlRequest, sh, &report, requestTypes)
if report.HasErrors() {
return stats, report
}
var typesFields = make(map[string][]string)
var rootFields []string
for t, fields := range requestTypes {
isRootOperationType := false
if t == string(g.schema.Index.QueryTypeName) || t == string(g.schema.Index.MutationTypeName) || t == string(g.schema.Index.SubscriptionTypeName) {
isRootOperationType = true
}
for field := range fields {
if isRootOperationType {
rootFields = append(rootFields, field)
} else {
typesFields[t] = append(typesFields[t], field)
}
}
}
stats.Types = typesFields
stats.RootFields = rootFields
stats.OperationType = g.AnalyticsOperationTypes()
graphErrors, err := g.GraphErrors([]byte(response))
for _, e := range graphErrors {
stats.Errors = append(stats.Errors, analytics.GraphError{
Message: e,
})
}
stats.HasErrors = len(stats.Errors) > 0
return stats, nil
}
Cognitive complexity: 24, Cyclomatic complexity: 12
func (*GraphStatsExtractionVisitor) GraphErrors
func (g *GraphStatsExtractionVisitor) GraphErrors(response []byte) ([]string, error) {
errs := make([]string, 0)
errBytes, t, _, err := jsonparser.Get(response, "errors")
// check if the errors key exists in the response
if err != nil {
if errors.Is(err, jsonparser.KeyPathNotFoundError) {
return nil, nil
}
return nil, err
}
if t != jsonparser.NotExist {
if _, err := jsonparser.ArrayEach(errBytes, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
message, err := jsonparser.GetString(value, "message")
if err != nil {
return
}
errs = append(errs, message)
}); err != nil {
return nil, err
}
}
return errs, nil
}
Cognitive complexity: 11, Cyclomatic complexity: 6
func (*MockExecutionEngineI) EXPECT
EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockExecutionEngineI) EXPECT() *MockExecutionEngineIMockRecorder {
return m.recorder
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineI) Execute
Execute mocks base method.
func (m *MockExecutionEngineI) Execute(ctx context.Context, operation *graphql.Request, writer resolve.FlushWriter, options ...graphql.ExecutionOptionsV2) error {
m.ctrl.T.Helper()
varargs := []interface{}{ctx, operation, writer}
for _, a := range options {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "Execute", varargs...)
ret0, _ := ret[0].(error)
return ret0
}
Cognitive complexity: 5, Cyclomatic complexity: 2
func (*MockExecutionEngineI) InputValidation
InputValidation mocks base method.
func (m *MockExecutionEngineI) InputValidation(operation *graphql.Request) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "InputValidation", operation)
ret0, _ := ret[0].(error)
return ret0
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineI) Normalize
Normalize mocks base method.
func (m *MockExecutionEngineI) Normalize(operation *graphql.Request) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Normalize", operation)
ret0, _ := ret[0].(error)
return ret0
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineI) Plan
Plan mocks base method.
func (m *MockExecutionEngineI) Plan(postProcessor *postprocess.Processor, operation *graphql.Request, report *operationreport.Report) (plan.Plan, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Plan", postProcessor, operation, report)
ret0, _ := ret[0].(plan.Plan)
ret1, _ := ret[1].(error)
return ret0, ret1
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineI) Resolve
Resolve mocks base method.
func (m *MockExecutionEngineI) Resolve(resolveContext *resolve.Context, planResult plan.Plan, writer resolve.FlushWriter) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Resolve", resolveContext, planResult, writer)
ret0, _ := ret[0].(error)
return ret0
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineI) Setup
Setup mocks base method.
func (m *MockExecutionEngineI) Setup(ctx context.Context, postProcessor *postprocess.Processor, resolveContext *resolve.Context, operation *graphql.Request, options ...graphql.ExecutionOptionsV2) {
m.ctrl.T.Helper()
varargs := []interface{}{ctx, postProcessor, resolveContext, operation}
for _, a := range options {
varargs = append(varargs, a)
}
m.ctrl.Call(m, "Setup", varargs...)
}
Cognitive complexity: 5, Cyclomatic complexity: 2
func (*MockExecutionEngineI) Teardown
Teardown mocks base method.
func (m *MockExecutionEngineI) Teardown() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Teardown")
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineI) ValidateForSchema
ValidateForSchema mocks base method.
func (m *MockExecutionEngineI) ValidateForSchema(operation *graphql.Request) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateForSchema", operation)
ret0, _ := ret[0].(error)
return ret0
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) Execute
Execute indicates an expected call of Execute.
func (mr *MockExecutionEngineIMockRecorder) Execute(ctx, operation, writer interface{}, options ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{ctx, operation, writer}, options...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockExecutionEngineI)(nil).Execute), varargs...)
}
Cognitive complexity: 4, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) InputValidation
InputValidation indicates an expected call of InputValidation.
func (mr *MockExecutionEngineIMockRecorder) InputValidation(operation interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InputValidation", reflect.TypeOf((*MockExecutionEngineI)(nil).InputValidation), operation)
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) Normalize
Normalize indicates an expected call of Normalize.
func (mr *MockExecutionEngineIMockRecorder) Normalize(operation interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Normalize", reflect.TypeOf((*MockExecutionEngineI)(nil).Normalize), operation)
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) Plan
Plan indicates an expected call of Plan.
func (mr *MockExecutionEngineIMockRecorder) Plan(postProcessor, operation, report interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Plan", reflect.TypeOf((*MockExecutionEngineI)(nil).Plan), postProcessor, operation, report)
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) Resolve
Resolve indicates an expected call of Resolve.
func (mr *MockExecutionEngineIMockRecorder) Resolve(resolveContext, planResult, writer interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resolve", reflect.TypeOf((*MockExecutionEngineI)(nil).Resolve), resolveContext, planResult, writer)
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) Setup
Setup indicates an expected call of Setup.
func (mr *MockExecutionEngineIMockRecorder) Setup(ctx, postProcessor, resolveContext, operation interface{}, options ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{ctx, postProcessor, resolveContext, operation}, options...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Setup", reflect.TypeOf((*MockExecutionEngineI)(nil).Setup), varargs...)
}
Cognitive complexity: 4, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) Teardown
Teardown indicates an expected call of Teardown.
func (mr *MockExecutionEngineIMockRecorder) Teardown() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Teardown", reflect.TypeOf((*MockExecutionEngineI)(nil).Teardown))
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*MockExecutionEngineIMockRecorder) ValidateForSchema
ValidateForSchema indicates an expected call of ValidateForSchema.
func (mr *MockExecutionEngineIMockRecorder) ValidateForSchema(operation interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateForSchema", reflect.TypeOf((*MockExecutionEngineI)(nil).ValidateForSchema), operation)
}
Cognitive complexity: 1, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Basic) Execute
func (o *OtelGraphqlEngineV2Basic) Execute(inCtx context.Context, operation *graphql.Request, writer resolve.FlushWriter, options ...graphql.ExecutionOptionsV2) error {
ctx, span := o.tracerProvider.Tracer().Start(inCtx, "GraphqlEngine")
defer span.End()
o.SetContext(ctx)
operationType, err := operation.OperationType()
if err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "failed to get operation type")
return err
}
span.SetAttributes(
semconv.GraphQLOperationName(operation.OperationName),
semconv.GraphQLOperationType(PrintOperationType(ast.OperationType(operationType))),
semconv.GraphQLDocument(operation.Query),
)
if err := o.executor.Execute(inCtx, operation, writer, options...); err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "failed to execute")
return err
}
return nil
}
Cognitive complexity: 4, Cyclomatic complexity: 3
func (*OtelGraphqlEngineV2Basic) InputValidation
func (o *OtelGraphqlEngineV2Basic) InputValidation(operation *graphql.Request) error {
return o.engine.InputValidation(operation)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Basic) Normalize
func (o *OtelGraphqlEngineV2Basic) Normalize(operation *graphql.Request) error {
opType, err := operation.OperationType()
if err != nil {
return err
}
err = o.engine.Normalize(operation)
if err != nil {
_, span := o.tracerProvider.Tracer().Start(o.traceContext, "GraphqlMiddleware Validation")
defer span.End()
span.SetAttributes(
semconv.GraphQLOperationName(operation.OperationName),
semconv.GraphQLOperationType(PrintOperationType(ast.OperationType(opType))),
semconv.GraphQLDocument(operation.Query),
)
return err
}
return nil
}
Cognitive complexity: 4, Cyclomatic complexity: 3
func (*OtelGraphqlEngineV2Basic) Plan
func (o *OtelGraphqlEngineV2Basic) Plan(postProcessor *postprocess.Processor, operation *graphql.Request, report *operationreport.Report) (plan.Plan, error) {
return o.engine.Plan(postProcessor, operation, report)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Basic) Resolve
func (o *OtelGraphqlEngineV2Basic) Resolve(resolveContext *resolve.Context, planResult plan.Plan, writer resolve.FlushWriter) error {
// Replacing the internal context is required to make a hierarchy between the execution and the upstream spans.
resolveContext = resolveContext.WithContext(o.traceContext)
return o.engine.Resolve(resolveContext, planResult, writer)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Basic) Setup
func (o *OtelGraphqlEngineV2Basic) Setup(ctx context.Context, postProcessor *postprocess.Processor, resolveContext *resolve.Context, operation *graphql.Request, options ...graphql.ExecutionOptionsV2) {
o.engine.Setup(ctx, postProcessor, resolveContext, operation, options...)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Basic) Teardown
func (o *OtelGraphqlEngineV2Basic) Teardown() {}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Basic) ValidateForSchema
func (o *OtelGraphqlEngineV2Basic) ValidateForSchema(operation *graphql.Request) error {
return o.engine.ValidateForSchema(operation)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Detailed) Execute
func (o *OtelGraphqlEngineV2Detailed) Execute(inCtx context.Context, operation *graphql.Request, writer resolve.FlushWriter, options ...graphql.ExecutionOptionsV2) error {
ctx, span := o.tracerProvider.Tracer().Start(inCtx, "GraphqlEngine")
defer span.End()
o.SetContext(ctx)
if err := o.executor.Execute(inCtx, operation, writer, options...); err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "failed to execute")
return err
}
return nil
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func (*OtelGraphqlEngineV2Detailed) InputValidation
func (o *OtelGraphqlEngineV2Detailed) InputValidation(operation *graphql.Request) error {
var operationName = "InputValidation"
_, span := o.tracerProvider.Tracer().Start(o.traceContext, operationName)
defer span.End()
if err := o.engine.InputValidation(operation); err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "failed input validation")
return err
}
return nil
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func (*OtelGraphqlEngineV2Detailed) Normalize
func (o *OtelGraphqlEngineV2Detailed) Normalize(operation *graphql.Request) error {
if operation.IsNormalized() {
return nil
}
var operationName = "NormalizeRequest"
_, span := o.tracerProvider.Tracer().Start(o.traceContext, operationName)
defer span.End()
err := o.engine.Normalize(operation)
if err != nil {
operationType, _ := operation.OperationType()
span.SetAttributes(
semconv.GraphQLOperationName(operation.OperationName),
semconv.GraphQLOperationType(PrintOperationType(ast.OperationType(operationType))),
semconv.GraphQLDocument(operation.Query),
)
span.SetStatus(otel.SPAN_STATUS_ERROR, "request normalization failed")
return err
}
return nil
}
Cognitive complexity: 4, Cyclomatic complexity: 3
func (*OtelGraphqlEngineV2Detailed) Plan
func (o *OtelGraphqlEngineV2Detailed) Plan(postProcessor *postprocess.Processor, operation *graphql.Request, report *operationreport.Report) (plan.Plan, error) {
var operationName = "GeneratePlan"
_, span := o.tracerProvider.Tracer().Start(o.traceContext, operationName)
defer span.End()
p, err := o.engine.Plan(postProcessor, operation, report)
if err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "failed to generate plan")
return nil, err
}
return p, nil
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func (*OtelGraphqlEngineV2Detailed) Resolve
func (o *OtelGraphqlEngineV2Detailed) Resolve(resolveContext *resolve.Context, planResult plan.Plan, writer resolve.FlushWriter) error {
var operationName = "ResolvePlan"
ctx, span := o.tracerProvider.Tracer().Start(o.traceContext, operationName)
defer span.End()
resolveContext = resolveContext.WithContext(ctx)
if err := o.engine.Resolve(resolveContext, planResult, writer); err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "failed to resolve")
return err
}
return nil
}
Cognitive complexity: 2, Cyclomatic complexity: 2
func (*OtelGraphqlEngineV2Detailed) Setup
func (o *OtelGraphqlEngineV2Detailed) Setup(ctx context.Context, postProcessor *postprocess.Processor, resolveContext *resolve.Context, operation *graphql.Request, options ...graphql.ExecutionOptionsV2) {
var operationName = "SetupResolver"
_, span := o.tracerProvider.Tracer().Start(o.traceContext, operationName)
defer span.End()
o.engine.Setup(ctx, postProcessor, resolveContext, operation, options...)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Detailed) Teardown
func (o *OtelGraphqlEngineV2Detailed) Teardown() {
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*OtelGraphqlEngineV2Detailed) ValidateForSchema
func (o *OtelGraphqlEngineV2Detailed) ValidateForSchema(operation *graphql.Request) error {
if operation.IsValidated(o.schema) {
return nil
}
var operationName = "ValidateRequest"
_, span := o.tracerProvider.Tracer().Start(o.traceContext, operationName)
defer span.End()
operationType, err := operation.OperationType()
if err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "request validation failed")
return err
}
span.SetAttributes(
semconv.GraphQLOperationName(operation.OperationName),
semconv.GraphQLOperationType(PrintOperationType(ast.OperationType(operationType))),
semconv.GraphQLDocument(operation.Query),
)
err = o.engine.ValidateForSchema(operation)
if err != nil {
span.SetStatus(otel.SPAN_STATUS_ERROR, "request validation failed")
return err
}
return nil
}
Cognitive complexity: 6, Cyclomatic complexity: 4
func (*otelGraphqlEngineV2Common) SetContext
func (o *otelGraphqlEngineV2Common) SetContext(ctx context.Context) {
o.mutex.Lock()
defer o.mutex.Unlock()
o.traceContext = ctx
}
Cognitive complexity: 0, Cyclomatic complexity: 1
Tests
Files: 3. Third party imports: 10. Imports from organisation: 6. Tests: 14. Benchmarks: 0.
Constants
const invalidSchema = `
schema {
query: Query
mutation: CustomMutation
}
input Characters{
}
type Query {
characters(filter: FilterCharacter, page: Int): Characters
listCharacters(): [Characters]!
}
type CustomMutation {
changeCharacter(): String
}
type Subscription {
listenCharacter(): Characters
}
input FilterCharacter {
name: String
status: String
species: String
type: String
gender: String! = "M"
}
type Characters {
info: Info
secondInfo: String
results: [Character]
}
type Info {
count: Int
next: Int
pages: Int
prev: Int
}
type Character {
gender: String
id: ID
name: String
}
type EmptyType{
}
`
const noSchema = `
schema {
query: Query
mutation: CustomMutation
`
// TODO fix when input named character
const validSchema = `
schema {
query: Que
mutation: CustomMutation
}
type Que {
characters(filter: FilterCharacter, page: Int): Characters
listCharacters(): [Characters]!
}
type CustomMutation {
changeCharacter(): String
}
type Subscription {
listenCharacter(): Characters
}
input FilterCharacter {
name: String
status: String
species: String
type: String
gender: String! = "M"
}
type Characters {
info: Info
secondInfo: String
results: [Character]
}
type Info {
count: Int
next: Int
pages: Int
prev: Int
}
type Character {
gender: String
id: ID
name: String
}
type EmptyType{
}
`
Vars
var namedRequest = graphql.Request{
OperationName: "MyQuery",
Query: `query MyQuery {
country(code: "TR"){
name
}
}`,
}
var request = graphql.Request{
Query: `{
country(code: "NG"){
name
}
}`,
}
var schema *graphql.Schema
var testSchema = `directive @cacheControl(maxAge: Int, scope: CacheControlScope) on FIELD_DEFINITION | OBJECT | INTERFACE
schema {
query: Query
}
interface CodeType {
code: ID!
}
interface CodeNameType implements CodeType {
code: ID!
name: String!
}
enum CacheControlScope {
PUBLIC
PRIVATE
}
type Continent implements CodeNameType & CodeType {
code: ID!
name: String!
countries: [Country!]!
}
input ContinentFilterInput {
code: StringQueryOperatorInput
}
type Country implements CodeNameType & CodeType {
code: ID!
name: String!
native: String!
phone: String!
continent: Continent!
capital: String
currency: String
languages: [Language!]!
emoji: String!
emojiU: String!
states: [State!]!
}
input CountryFilterInput {
code: StringQueryOperatorInput
currency: StringQueryOperatorInput
continent: StringQueryOperatorInput
}
type Language {
code: ID!
name: String
native: String
rtl: Boolean!
}
input LanguageFilterInput {
code: StringQueryOperatorInput
}
type Query {
continents(filter: ContinentFilterInput): [Continent!]!
continent(code: ID!): Continent
countries(filter: CountryFilterInput): [Country!]!
country(code: ID!): Country
languages(filter: LanguageFilterInput): [Language!]!
language(code: ID!): Language
codeType: CodeType!
}
type State {
code: String
name: String!
country: Country!
}
input StringQueryOperatorInput {
eq: String
ne: String
in: [String]
nin: [String]
regex: String
glob: String
}
"""The Upload scalar type represents a file upload."""
scalar Upload`
var tracerProvider otel.TracerProvider
Types
spanWrapper
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. | |
| name |
|
No comment on field. |
| span |
|
No comment on field. |
| attributes |
|
No comment on field. |
type spanWrapper struct {
embedded.Span
name string
span trace.Span
attributes map[string][]attribute.KeyValue
}
tracerProviderWrapper
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| provider |
|
No comment on field. |
| spanAttributes |
|
No comment on field. |
type tracerProviderWrapper struct {
provider tyktrace.Provider
spanAttributes map[string][]attribute.KeyValue
}
tracerWrapper
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. | |
| tracer |
|
No comment on field. |
| spanAttributes |
|
No comment on field. |
type tracerWrapper struct {
embedded.Tracer
tracer tyktrace.Tracer
spanAttributes map[string][]attribute.KeyValue
}