Go API Documentation

github.com/TykTechnologies/tyk/apidef/adapter

No package summary is available.

Package

Files: 5. Third party imports: 1. Imports from organisation: 9. Tests: 0. Benchmarks: 0.

Constants

const (
	KafkaGroupIdKey		= "groupId"
	KafkaClientIdKey	= "clientId"
)
const (
	GraphQLTypeQuery	= "Query"
	GraphQLTypeMutation	= "Mutation"
)
const (
	GraphQLEngineAdapterTypeUnknown	= iota
	GraphQLEngineAdapterTypeProxyOnly
	GraphQLEngineAdapterTypeSupergraph
	GraphQLEngineAdapterTypeUniversalDataGraph
)
const defaultRequestBodyMimeType = "application/json"

Vars

var ErrUnsupportedGraphQLConfigVersion = errors.New("provided version of GraphQL config is not supported for this operation")
var ErrUnsupportedGraphQLExecutionMode = errors.New("provided execution mode of GraphQL config is not supported for this operation")
var _ ImportAdapter = (*asyncAPI)(nil)

Types

GraphQLConfigAdapter

This type doesn't have documentation.

Field name Field type Comment
apiDefinition

*apidef.APIDefinition

No comment on field.
httpClient

*http.Client

No comment on field.
streamingClient

*http.Client

No comment on field.
schema

*graphql.Schema

No comment on field.
schemaV2

*gqlv2.Schema

No comment on field.
type GraphQLConfigAdapter struct {
	apiDefinition	*apidef.APIDefinition
	httpClient	*http.Client
	streamingClient	*http.Client
	schema		*graphql.Schema
	schemaV2	*gqlv2.Schema
}

GraphQLConfigAdapterOption

This type doesn't have documentation.

Field name Field type Comment
type

func(adapter *GraphQLConfigAdapter)

No comment on field.
type GraphQLConfigAdapterOption func(adapter *GraphQLConfigAdapter)

GraphQLEngineAdapter

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type GraphQLEngineAdapter interface {
	EngineConfig() (*graphql.EngineV2Configuration, error)
}

GraphQLEngineAdapterType

This type doesn't have documentation.

Field name Field type Comment
type

int

No comment on field.
type GraphQLEngineAdapterType int

GraphQLEngineAdapterV3

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type GraphQLEngineAdapterV3 interface {
	EngineConfigV3() (*gqlv2.EngineV2Configuration, error)
}

ImportAdapter

This type doesn't have documentation.

Field name Field type Comment
type

any

No comment on field.
type ImportAdapter interface {
	Import() (*apidef.APIDefinition, error)
}

asyncAPI

This type doesn't have documentation.

Field name Field type Comment
orgId

string

No comment on field.
input

[]byte

No comment on field.
report

*operationreport.Report

No comment on field.
apiDefinition

*apidef.APIDefinition

No comment on field.
document

*asyncapi.AsyncAPI

No comment on field.
type asyncAPI struct {
	orgId		string
	input		[]byte
	report		*operationreport.Report
	apiDefinition	*apidef.APIDefinition
	document	*asyncapi.AsyncAPI
}

openAPI

This type doesn't have documentation.

Field name Field type Comment
orgId

string

No comment on field.
input

[]byte

No comment on field.
report

*operationreport.Report

No comment on field.
apiDefinition

*apidef.APIDefinition

No comment on field.
document

*openapi3.T

No comment on field.
type openAPI struct {
	orgId		string
	input		[]byte
	report		*operationreport.Report
	apiDefinition	*apidef.APIDefinition
	document	*openapi3.T
}

Functions

func NewAsyncAPIAdapter

func NewAsyncAPIAdapter(orgId string, input []byte) ImportAdapter {
	return &asyncAPI{
		orgId:	orgId,
		input:	input,
		report:	&operationreport.Report{},
	}
}

Cognitive complexity: 2, Cyclomatic complexity: 1

Uses: operationreport.Report.

func NewGraphQLConfigAdapter

func NewGraphQLConfigAdapter(apiDefinition *apidef.APIDefinition, options ...GraphQLConfigAdapterOption) GraphQLConfigAdapter {
	adapter := GraphQLConfigAdapter{
		apiDefinition: apiDefinition,
	}
	for _, option := range options {
		option(&adapter)
	}

	return adapter
}

Cognitive complexity: 4, Cyclomatic complexity: 2

func NewOpenAPIAdapter

func NewOpenAPIAdapter(orgId string, input []byte) ImportAdapter {
	report := operationreport.Report{}
	return &openAPI{
		report:	&report,
		input:	input,
		orgId:	orgId,
	}
}

Cognitive complexity: 2, Cyclomatic complexity: 1

Uses: operationreport.Report.

func WithHttpClient

func WithHttpClient(httpClient *http.Client) GraphQLConfigAdapterOption {
	return func(adapter *GraphQLConfigAdapter) {
		adapter.httpClient = httpClient
	}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func WithSchema

func WithSchema(schema *graphql.Schema) GraphQLConfigAdapterOption {
	return func(adapter *GraphQLConfigAdapter) {
		adapter.schema = schema
	}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func WithStreamingClient

func WithStreamingClient(streamingClient *http.Client) GraphQLConfigAdapterOption {
	return func(adapter *GraphQLConfigAdapter) {
		adapter.streamingClient = streamingClient
	}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func WithV2Schema

func WithV2Schema(schema *gqlv2.Schema) GraphQLConfigAdapterOption {
	return func(adapter *GraphQLConfigAdapter) {
		adapter.schemaV2 = schema
	}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func (*GraphQLConfigAdapter) EngineConfigV2

func (g *GraphQLConfigAdapter) EngineConfigV2() (*graphql.EngineV2Configuration, error) {
	if g.apiDefinition.GraphQL.Version != apidef.GraphQLConfigVersion2 {
		return nil, ErrUnsupportedGraphQLConfigVersion
	}

	var engineAdapter GraphQLEngineAdapter
	adapterType := graphqlEngineAdapterTypeFromApiDefinition(g.apiDefinition)
	switch adapterType {
	case GraphQLEngineAdapterTypeProxyOnly:
		engineAdapter = &gqlengineadapter.ProxyOnly{
			ApiDefinition:		g.apiDefinition,
			HttpClient:		g.getHttpClient(),
			StreamingClient:	g.getStreamingClient(),
			Schema:			g.schema,
		}
	case GraphQLEngineAdapterTypeSupergraph:
		engineAdapter = &gqlengineadapter.Supergraph{
			ApiDefinition:		g.apiDefinition,
			HttpClient:		g.getHttpClient(),
			StreamingClient:	g.getStreamingClient(),
		}
	case GraphQLEngineAdapterTypeUniversalDataGraph:
		engineAdapter = &gqlengineadapter.UniversalDataGraph{
			ApiDefinition:		g.apiDefinition,
			HttpClient:		g.getHttpClient(),
			StreamingClient:	g.getStreamingClient(),
			Schema:			g.schema,
		}
	default:
		return nil, ErrUnsupportedGraphQLExecutionMode
	}

	return engineAdapter.EngineConfig()
}

Cognitive complexity: 10, Cyclomatic complexity: 6

Uses: apidef.GraphQLConfigVersion2, gqlengineadapter.ProxyOnly, gqlengineadapter.Supergraph, gqlengineadapter.UniversalDataGraph.

func (*GraphQLConfigAdapter) EngineConfigV3

func (g *GraphQLConfigAdapter) EngineConfigV3() (*gqlv2.EngineV2Configuration, error) {
	if g.apiDefinition.GraphQL.Version != apidef.GraphQLConfigVersion3Preview {
		return nil, ErrUnsupportedGraphQLConfigVersion
	}

	var engineAdapter GraphQLEngineAdapterV3
	adapterType := graphqlEngineAdapterTypeFromApiDefinition(g.apiDefinition)
	switch adapterType {
	case GraphQLEngineAdapterTypeProxyOnly:
		engineAdapter = &v3adapter.ProxyOnly{
			ApiDefinition:		g.apiDefinition,
			HttpClient:		g.getHttpClient(),
			StreamingClient:	g.getStreamingClient(),
			Schema:			g.schemaV2,
		}
	case GraphQLEngineAdapterTypeSupergraph:
		return nil, ErrUnsupportedGraphQLConfigVersion
	case GraphQLEngineAdapterTypeUniversalDataGraph:
		engineAdapter = &v3adapter.UniversalDataGraph{
			ApiDefinition:		g.apiDefinition,
			HttpClient:		g.getHttpClient(),
			StreamingClient:	g.getStreamingClient(),
			Schema:			g.schemaV2,
		}
	default:
		return nil, ErrUnsupportedGraphQLExecutionMode
	}

	return engineAdapter.EngineConfigV3()
}

Cognitive complexity: 9, Cyclomatic complexity: 6

Uses: apidef.GraphQLConfigVersion3Preview, v3adapter.ProxyOnly, v3adapter.UniversalDataGraph.

func (*asyncAPI) Import

func (a *asyncAPI) Import() (*apidef.APIDefinition, error) {
	document, err := asyncapi.ParseAsyncAPIDocument(a.input)
	if err != nil {
		return nil, err
	}

	a.document = document
	a.apiDefinition = newApiDefinition(document.Info.Title, a.orgId)

	if err := a.prepareGraphQLEngineConfig(); err != nil {
		return nil, err
	}

	// We iterate over the maps to create a new API definition. This leads to the random placement of
	// items in various arrays in the resulting JSON document. In order to test the AsyncAPI converter
	// with fixtures and prevent randomness, we sort various data structures here.
	sortFieldConfigsByName(a.apiDefinition)
	sortDataSourcesByName(a.apiDefinition)

	gqlDocument := asyncapi.ImportParsedAsyncAPIDocument(a.document, a.report)
	if a.report.HasErrors() {
		return nil, a.report
	}

	w := &bytes.Buffer{}
	err = astprinter.PrintIndent(gqlDocument, nil, []byte("  "), w)
	if err != nil {
		return nil, err
	}
	a.apiDefinition.GraphQL.Schema = w.String()

	return a.apiDefinition, nil
}

Cognitive complexity: 9, Cyclomatic complexity: 5

Uses: astprinter.PrintIndent, asyncapi.ImportParsedAsyncAPIDocument, asyncapi.ParseAsyncAPIDocument, bytes.Buffer.

func (*openAPI) Import

func (o *openAPI) Import() (*apidef.APIDefinition, error) {
	document, err := openapi.ParseOpenAPIDocument(o.input)
	if err != nil {
		return nil, err
	}

	o.document = document
	o.apiDefinition = newApiDefinition(o.document.Info.Title, o.orgId)

	if err := o.prepareGraphQLEngineConfig(); err != nil {
		return nil, err
	}

	// We iterate over the maps to create a new API definition. This leads to the random placement of
	// items in various arrays in the resulting JSON document. In order to test the OpenAPI converter
	// with fixtures and prevent randomness, we sort various data structures here.
	sortFieldConfigsByName(o.apiDefinition)
	sortDataSourcesByName(o.apiDefinition)

	graphqlDocument := openapi.ImportParsedOpenAPIv3Document(o.document, o.report)
	if o.report.HasErrors() {
		return nil, o.report
	}

	w := &bytes.Buffer{}
	err = astprinter.PrintIndent(graphqlDocument, nil, []byte("  "), w)
	if err != nil {
		return nil, err
	}
	o.apiDefinition.GraphQL.Schema = w.String()

	return o.apiDefinition, nil
}

Cognitive complexity: 9, Cyclomatic complexity: 5

Uses: astprinter.PrintIndent, bytes.Buffer, openapi.ImportParsedOpenAPIv3Document, openapi.ParseOpenAPIDocument.

Private functions

func encodeKafkaDataSourceConfig

encodeKafkaDataSourceConfig (cfg kafkadatasource.GraphQLSubscriptionOptions, topic string) ([]byte, error)
References: json.Marshal.

func extractRequestBody

extractRequestBody (mime string, operation *openapi3.Operation) (*openapi3.SchemaRef, error)
References: fmt.Errorf.

func graphqlEngineAdapterTypeFromApiDefinition

graphqlEngineAdapterTypeFromApiDefinition (apiDefinition *apidef.APIDefinition) GraphQLEngineAdapterType

func isProxyOnlyAPIDefinition

isProxyOnlyAPIDefinition (apiDefinition *apidef.APIDefinition) bool
References: apidef.GraphQLExecutionModeProxyOnly, apidef.GraphQLExecutionModeSubgraph.

func isSupergraphAPIDefinition

isSupergraphAPIDefinition (apiDefinition *apidef.APIDefinition) bool
References: apidef.GraphQLExecutionModeSupergraph.

func isUniversalDataGraphAPIDefinition

isUniversalDataGraphAPIDefinition (apiDefinition *apidef.APIDefinition) bool
References: apidef.GraphQLExecutionModeExecutionEngine.

func newApiDefinition

newApiDefinition (name,orgId string) *apidef.APIDefinition
References: apidef.APIDefinition, apidef.GraphQLConfig, apidef.GraphQLConfigVersion2, apidef.GraphQLExecutionModeExecutionEngine, apidef.GraphQLProxyConfig, apidef.ProxyConfig, apidef.VersionData, apidef.VersionDefinition, apidef.VersionInfo, uuid.NewHex.

func prepareKafkaDataSourceConfig

prepareKafkaDataSourceConfig (parsed *asyncapi.AsyncAPI) (map[string]kafkadatasource.GraphQLSubscriptionOptions, error)
References: asyncapi.KafkaKey, fmt.Errorf, jsonparser.String, kafkadatasource.GraphQLSubscriptionOptions.

func processArgumentSection

processArgumentSection (input string) string
References: fmt.Sprintf, regexp.MustCompile, strings.ReplaceAll.

func removeCurlyBraces

removeCurlyBraces (argument string) string
References: strings.Map.

func sortDataSourcesByName

sortDataSourcesByName (apiDefinition *apidef.APIDefinition)
References: sort.Slice.

func sortFieldConfigsByName

sortFieldConfigsByName (apiDefinition *apidef.APIDefinition)
References: sort.Slice.

func getHttpClient

getHttpClient () *http.Client
References: httpclient.DefaultNetHttpClient.

func getStreamingClient

getStreamingClient () *http.Client
References: httpclient.DefaultNetHttpClient.

func prepareGraphQLEngineConfig

prepareGraphQLEngineConfig () error
References: apidef.GraphQLEngineDataSource, apidef.GraphQLEngineDataSourceKindKafka, apidef.GraphQLFieldConfig, apidef.GraphQLTypeFields, fmt.Sprintf.

func prepareGraphQLEngineConfig

prepareGraphQLEngineConfig () error
References: apidef.GraphQLEngineDataSource, apidef.GraphQLEngineDataSourceConfigREST, apidef.GraphQLEngineDataSourceKindREST, apidef.GraphQLFieldConfig, apidef.GraphQLTypeFields, apidef.QueryVariable, errors.New, fmt.Errorf, fmt.Sprintf, http.MethodDelete, http.MethodGet, http.MethodPost, http.MethodPut, json.Marshal, openapi.MakeFieldNameFromEndpoint, openapi.MakeFieldNameFromEndpointForMutation, openapi.MakeFieldNameFromOperationID, openapi.MakeInputTypeName, openapi.MakeParameterName, path.Join, url.Parse, url.PathUnescape.


Tests

Files: 4. Third party imports: 3. Imports from organisation: 0. Tests: 7. Benchmarks: 0.

Constants

const expectedGraphqlConfig = `{
    "enabled": true,
    "execution_mode": "executionEngine",
    "version": "2",
    "schema": "schema {\n    query: Query\n    subscription: Subscription\n}\n\ntype Query {\n    _: Boolean\n}\n\ntype Subscription {\n    dimLight(streetlightId: String): DimLight\n    turnOff(streetlightId: String): TurnOnOff\n    turnOn(streetlightId: String): TurnOnOff\n}\n\nenum Command {\n    ON\n    OFF\n}\n\n\"\"\"\nDim light\nCommand a particular streetlight to dim the lights.\n\"\"\"\ntype DimLight {\n    \"Percentage to which the light should be dimmed to.\"\n    percentage: Int\n    \"Date and time when the message was sent.\"\n    sentAt: String\n}\n\n\"\"\"\nTurn on/off\nCommand a particular streetlight to turn the lights on or off.\n\"\"\"\ntype TurnOnOff {\n    \"Whether to turn on or off the light.\"\n    command: Command\n    \"Date and time when the message was sent.\"\n    sentAt: String\n}",
    "type_field_configurations": null,
    "playground": {
        "enabled": false,
        "path": ""
    },
    "engine": {
        "field_configs": [
            {
                "type_name": "Subscription",
                "field_name": "dimLight",
                "disable_default_mapping": false,
                "path": [
                    "dimLight"
                ]
            },
            {
                "type_name": "Subscription",
                "field_name": "turnOff",
                "disable_default_mapping": false,
                "path": [
                    "turnOff"
                ]
            },
            {
                "type_name": "Subscription",
                "field_name": "turnOn",
                "disable_default_mapping": false,
                "path": [
                    "turnOn"
                ]
            }
        ],
        "data_sources": [
            {
                "kind": "Kafka",
                "name": "consumer-group:dimLight",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Subscription",
                        "fields": [
                            "dimLight"
                        ]
                    }
                ],
                "config": {
                    "broker_addresses": [
                        "test.mykafkacluster.org:8092"
                    ],
                    "topics": [
                        "smartylighting.streetlights.1.0.action.{{.arguments.streetlightId}}.dim"
                    ],
                    "group_id": "my-group-id",
                    "client_id": "my-app-id",
                    "kafka_version": "V1_0_0_0",
                    "start_consuming_latest": false,
                    "balance_strategy": "BalanceStrategyRange",
                    "isolation_level": "ReadUncommitted",
                    "sasl": {
                        "enable": false,
                        "user": "",
                        "password": ""
                    }
                }
            },
            {
                "kind": "Kafka",
                "name": "consumer-group:turnOff",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Subscription",
                        "fields": [
                            "turnOff"
                        ]
                    }
                ],
                "config": {
                    "broker_addresses": [
                        "test.mykafkacluster.org:8092"
                    ],
                    "topics": [
                        "smartylighting.streetlights.1.0.action.{{.arguments.streetlightId}}.turn.off"
                    ],
                    "group_id": "my-group-id",
                    "client_id": "my-app-id",
                    "kafka_version": "V1_0_0_0",
                    "start_consuming_latest": false,
                    "balance_strategy": "BalanceStrategyRange",
                    "isolation_level": "ReadUncommitted",
                    "sasl": {
                        "enable": false,
                        "user": "",
                        "password": ""
                    }
                }
            },
            {
                "kind": "Kafka",
                "name": "consumer-group:turnOn",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Subscription",
                        "fields": [
                            "turnOn"
                        ]
                    }
                ],
                "config": {
                    "broker_addresses": [
                        "test.mykafkacluster.org:8092"
                    ],
                    "topics": [
                        "smartylighting.streetlights.1.0.action.{{.arguments.streetlightId}}.turn.on"
                    ],
                    "group_id": "my-group-id",
                    "client_id": "my-app-id",
                    "kafka_version": "V1_0_0_0",
                    "start_consuming_latest": false,
                    "balance_strategy": "BalanceStrategyRange",
                    "isolation_level": "ReadUncommitted",
                    "sasl": {
                        "enable": false,
                        "user": "",
                        "password": ""
                    }
                }
            }
        ],
        "global_headers": null
    },
    "proxy": {
        "features": {
            "use_immutable_headers": false
        },
        "auth_headers": {},
        "request_headers": null,
        "use_response_extensions": {
            "on_error_forwarding": false
        },
        "request_headers_rewrite": null
    },
    "subgraph": {
        "sdl": ""
    },
    "supergraph": {
        "subgraphs": null,
        "merged_sdl": "",
        "global_headers": null,
        "disable_query_batching": false
    },
    "introspection": {
        "disabled": false
    }
}`
const expectedOpenAPIGraphQLConfig = `{
    "enabled": true,
    "execution_mode": "executionEngine",
    "version": "2",
    "schema": "schema {\n    query: Query\n    mutation: Mutation\n}\n\ntype Query {\n    \"Returns a user based on a single ID, if the user does not have access to the pet\"\n    findPetById(id: Int!): Pet\n    \"\"\"\n    Returns all pets from the system that the user has access to\n    Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\n    Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n    \"\"\"\n    findPets(limit: Int, tags: [String]): [Pet]\n}\n\ntype Mutation {\n    \"Creates a new pet in the store. Duplicates are allowed\"\n    addPet(newPetInput: NewPetInput!): Pet\n    \"deletes a single pet based on the ID supplied\"\n    deletePet(id: Int!): String\n}\n\ninput NewPetInput {\n    name: String!\n    tag: String\n}\n\ntype Pet {\n    id: Int!\n    name: String!\n    tag: String\n}",
    "type_field_configurations": null,
    "playground": {
        "enabled": false,
        "path": ""
    },
    "engine": {
        "field_configs": [
            {
                "type_name": "Mutation",
                "field_name": "addPet",
                "disable_default_mapping": true,
                "path": [
                    "addPet"
                ]
            },
            {
                "type_name": "Mutation",
                "field_name": "deletePet",
                "disable_default_mapping": true,
                "path": [
                    "deletePet"
                ]
            },
            {
                "type_name": "Query",
                "field_name": "findPetById",
                "disable_default_mapping": true,
                "path": [
                    "findPetById"
                ]
            },
            {
                "type_name": "Query",
                "field_name": "findPets",
                "disable_default_mapping": true,
                "path": [
                    "findPets"
                ]
            }
        ],
        "data_sources": [
            {
                "kind": "REST",
                "name": "addPet",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Mutation",
                        "fields": [
                            "addPet"
                        ]
                    }
                ],
                "config": {
                    "url": "http://petstore.swagger.io/api/pets",
                    "method": "POST",
                    "headers": {},
                    "query": [],
                    "body": "{{ .arguments.newPetInput }}"
                }
            },
            {
                "kind": "REST",
                "name": "deletePet",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Mutation",
                        "fields": [
                            "deletePet"
                        ]
                    }
                ],
                "config": {
                    "url": "http://petstore.swagger.io/api/pets/{{.arguments.id}}",
                    "method": "DELETE",
                    "headers": {},
                    "query": [],
                    "body": ""
                }
            },
            {
                "kind": "REST",
                "name": "findPetById",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Query",
                        "fields": [
                            "findPetById"
                        ]
                    }
                ],
                "config": {
                    "url": "http://petstore.swagger.io/api/pets/{{.arguments.id}}",
                    "method": "GET",
                    "headers": {},
                    "query": [],
                    "body": ""
                }
            },
            {
                "kind": "REST",
                "name": "findPets",
                "internal": false,
                "root_fields": [
                    {
                        "type": "Query",
                        "fields": [
                            "findPets"
                        ]
                    }
                ],
                "config": {
                    "url": "http://petstore.swagger.io/api/pets?limit={{.arguments.limit}}\u0026tags={{.arguments.tags}}",
                    "method": "GET",
                    "headers": {},
                    "query": [],
                    "body": ""
                }
            }
        ],
        "global_headers": null
    },
    "proxy": {
        "features": {
            "use_immutable_headers": false
        },
        "auth_headers": {},
        "request_headers": null,
        "use_response_extensions": {
            "on_error_forwarding": false
        },
        "request_headers_rewrite": null
    },
    "subgraph": {
        "sdl": ""
    },
    "supergraph": {
        "subgraphs": null,
        "merged_sdl": "",
        "global_headers": null,
        "disable_query_batching": false
    },
    "introspection": {
        "disabled": false
    }
}`
const expectedOpenAPIGraphQLSchema = "schema {\n    query: Query\n    mutation: Mutation\n}\n\ntype Query {\n    \"Returns a user based on a single ID, if the user does not have access to the pet\"\n    findPetById(id: Int!): Pet\n    \"\"\"\n    Returns all pets from the system that the user has access to\n    Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\n    Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n    \"\"\"\n    findPets(limit: Int, tags: [String]): [Pet]\n}\n\ntype Mutation {\n    \"Creates a new pet in the store. Duplicates are allowed\"\n    addPet(newPetInput: NewPetInput!): Pet\n    \"deletes a single pet based on the ID supplied\"\n    deletePet(id: Int!): String\n}\n\ninput NewPetInput {\n    name: String!\n    tag: String\n}\n\ntype Pet {\n    id: Int!\n    name: String!\n    tag: String\n}"
const expectedSchema = "schema {\n    query: Query\n    subscription: Subscription\n}\n\ntype Query {\n    _: Boolean\n}\n\ntype Subscription {\n    dimLight(streetlightId: String): DimLight\n    turnOff(streetlightId: String): TurnOnOff\n    turnOn(streetlightId: String): TurnOnOff\n}\n\nenum Command {\n    ON\n    OFF\n}\n\n\"\"\"\nDim light\nCommand a particular streetlight to dim the lights.\n\"\"\"\ntype DimLight {\n    \"Percentage to which the light should be dimmed to.\"\n    percentage: Int\n    \"Date and time when the message was sent.\"\n    sentAt: String\n}\n\n\"\"\"\nTurn on/off\nCommand a particular streetlight to turn the lights on or off.\n\"\"\"\ntype TurnOnOff {\n    \"Whether to turn on or off the light.\"\n    command: Command\n    \"Date and time when the message was sent.\"\n    sentAt: String\n}"
const graphqlEngineUnknownExecutionMode = `{
	"enabled": true,
	"execution_mode": "unknown",
	"version": "2",
	"schema": "type Query { rest: String, gql: String }",
	"last_schema_update": "2020-11-11T11:11:11.000+01:00",
	"playground": {}
}`
const graphqlEngineV1ConfigJson = `{
	"enabled": true,
	"execution_mode": "executionEngine",
	"schema": "type Query { rest: String, gql: String }",
	"last_schema_update": "2020-11-11T11:11:11.000+01:00",
	"playground": {}
}`
const petstoreExpandedOpenAPI3 = `openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
  termsOfService: http://swagger.io/terms/
  contact:
    name: Swagger API Team
    email: apiteam@swagger.io
    url: http://swagger.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: http://petstore.swagger.io/api
paths:
  /pets:
    get:
      description: |
        Returns all pets from the system that the user has access to
        Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.

        Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.
      operationId: findPets
      parameters:
        - name: tags
          in: query
          description: tags to filter by
          required: false
          style: form
          schema:
            type: array
            items:
              type: string
        - name: limit
          in: query
          description: maximum number of results to return
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    post:
      description: Creates a new pet in the store. Duplicates are allowed
      operationId: addPet
      requestBody:
        description: Pet to add to the store
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewPet'
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /pets/{id}:
    get:
      description: Returns a user based on a single ID, if the user does not have access to the pet
      operationId: find pet by id
      parameters:
        - name: id
          in: path
          description: ID of pet to fetch
          required: true
          schema:
            type: integer
            format: int64
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    delete:
      description: deletes a single pet based on the ID supplied
      operationId: deletePet
      parameters:
        - name: id
          in: path
          description: ID of pet to delete
          required: true
          schema:
            type: integer
            format: int64
      responses:
        '204':
          description: pet deleted
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Pet:
      allOf:
        - $ref: '#/components/schemas/NewPet'
        - type: object
          required:
            - id
          properties:
            id:
              type: integer
              format: int64

    NewPet:
      type: object
      required:
        - name
      properties:
        name:
          type: string
        tag:
          type: string

    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string`
const streetlightsKafkaAsyncAPI = `asyncapi: '2.4.0'
info:
  title: Streetlights Kafka API
  version: '1.0.0'
  description: |
    The Smartylighting Streetlights API allows you to remotely manage the city lights.

    ### Check out its awesome features:

    * Turn a specific streetlight on/off 🌃
    * Dim a specific streetlight 😎
    * Receive real-time information about environmental lighting conditions 📈
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0

servers:
  test:
    url: test.mykafkacluster.org:8092
    protocol: kafka-secure
    description: Test broker
    bindings:
      kafka:
        clientId: my-app-id
        groupId: my-group-id
    security:
      - saslScram: []

defaultContentType: application/json

channels:
  smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured:
    description: The topic on which measured values may be produced and consumed.
    parameters:
      streetlightId:
        $ref: '#/components/parameters/streetlightId'
    publish:
      summary: Inform about environmental lighting conditions of a particular streetlight.
      operationId: receiveLightMeasurement
      traits:
        - $ref: '#/components/operationTraits/kafka'
      message:
        $ref: '#/components/messages/lightMeasured'

  smartylighting.streetlights.1.0.action.{streetlightId}.turn.on:
    parameters:
      streetlightId:
        $ref: '#/components/parameters/streetlightId'
    subscribe:
      operationId: turnOn
      traits:
        - $ref: '#/components/operationTraits/kafka'
      message:
        $ref: '#/components/messages/turnOnOff'

  smartylighting.streetlights.1.0.action.{streetlightId}.turn.off:
    parameters:
      streetlightId:
        $ref: '#/components/parameters/streetlightId'
    subscribe:
      operationId: turnOff
      traits:
        - $ref: '#/components/operationTraits/kafka'
      message:
        $ref: '#/components/messages/turnOnOff'

  smartylighting.streetlights.1.0.action.{streetlightId}.dim:
    parameters:
      streetlightId:
        $ref: '#/components/parameters/streetlightId'
    subscribe:
      operationId: dimLight
      traits:
        - $ref: '#/components/operationTraits/kafka'
      message:
        $ref: '#/components/messages/dimLight'

components:
  messages:
    lightMeasured:
      name: lightMeasured
      title: Light measured
      summary: Inform about environmental lighting conditions of a particular streetlight.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/commonHeaders'
      payload:
        $ref: "#/components/schemas/lightMeasuredPayload"
    turnOnOff:
      name: turnOnOff
      title: Turn on/off
      summary: Command a particular streetlight to turn the lights on or off.
      traits:
        - $ref: '#/components/messageTraits/commonHeaders'
      payload:
        $ref: "#/components/schemas/turnOnOffPayload"
    dimLight:
      name: dimLight
      title: Dim light
      summary: Command a particular streetlight to dim the lights.
      traits:
        - $ref: '#/components/messageTraits/commonHeaders'
      payload:
        $ref: "#/components/schemas/dimLightPayload"

  schemas:
    lightMeasuredPayload:
      type: object
      properties:
        lumens:
          type: integer
          minimum: 0
          description: Light intensity measured in lumens.
        sentAt:
          $ref: "#/components/schemas/sentAt"
    turnOnOffPayload:
      type: object
      properties:
        command:
          type: string
          enum:
            - on
            - off
          description: Whether to turn on or off the light.
        sentAt:
          $ref: "#/components/schemas/sentAt"
    dimLightPayload:
      type: object
      properties:
        percentage:
          type: integer
          description: Percentage to which the light should be dimmed to.
          minimum: 0
          maximum: 100
        sentAt:
          $ref: "#/components/schemas/sentAt"
    sentAt:
      type: string
      format: date-time
      description: Date and time when the message was sent.

  securitySchemes:
    saslScram:
      type: scramSha256
      description: Provide your username and password for SASL/SCRAM authentication

  parameters:
    streetlightId:
      description: The ID of the streetlight.
      schema:
        type: string

  messageTraits:
    commonHeaders:
      headers:
        type: object
        properties:
          my-app-header:
            type: integer
            minimum: 0
            maximum: 100

  operationTraits:
    kafka:
      bindings:
        kafka:
          clientId:
            type: string
            enum: ['my-app-id']`

Vars

var graphqlMinimalProxyOnlyConfig = `{
	"enabled": true,
	"execution_mode": "proxyOnly",
	"version": "2",
	"schema": "type Query { hello(name: String!): String! }",
	"last_schema_update": "2020-11-11T11:11:11.000+01:00",
	"proxy": {
		"auth_headers": {
			"Authorization": "123abc"
		},
		"subscription_type": "sse"
	},
	"engine": {
		"field_configs": [],
		"data_sources": []
	},
	"supergraph": {
		"subgraphs": [],
		"global_headers": {},
		"merged_sdl": ""
	},
	"playground": {}
}`
var graphqlMinimalSubgraphConfig = `{
	"enabled": true,
	"execution_mode": "subgraph",
	"version": "2",
	"schema": "type Query { hello: String }",
	"last_schema_update": "2020-11-11T11:11:11.000+01:00",
	"proxy": {
		"auth_headers": {
			"Authorization": "123abc"
		}
	},
	"engine": {
		"field_configs": [],
		"data_sources": []
	},
	"subgraph": {
		"sdl": "extend type Query { hello: String }",
		"subscription_type": "graphql-transport-ws"
	},
	"playground": {}
}`
var graphqlMinimalSupergraphConfig = `{
	"enabled": true,
	"execution_mode": "supergraph",
	"version": "2",
	"schema": "",
	"last_schema_update": "2020-11-11T11:11:11.000+01:00",
	"engine": {
		"field_configs": [],
		"data_sources": []
	},
	"supergraph": {
		"subgraphs": [
			{
				"api_id": "",
				"url": "tyk://accounts.service",
				"sdl": "extend type Query {me: User}",
				"headers": {},
				"subscription_type": "sse"
			}
		],
		"global_headers": {},
		"merged_sdl": "type Query { me: User }"
	},
	"playground": {}
}`
var graphqlMinimalUniversalDataGraphConfig = `{
	"enabled": true,
	"execution_mode": "executionEngine",
	"version": "2",
	"schema": "type Query { hello: String }",
	"last_schema_update": "2020-11-11T11:11:11.000+01:00",
	"engine": {
		"field_configs": [
			{
				"type_name": "Query",
				"field_name": "hello",
				"disable_default_mapping": false
			}
		],
		"data_sources": [
			{
				"kind": "REST",
				"name": "",
				"internal": true,
				"root_fields": [
					{ "type": "Query", "fields": ["hello"] }
				],
				"config": {
					"url": "tyk://rest-example",
					"method": "POST",
					"headers": {},
					"query": [],
					"body": ""
				}
			}
		]
	},
	"playground": {}
}`

Test functions

TestGraphQLConfigAdapter_AsyncAPI

References: apidef.GraphQLExecutionModeExecutionEngine, bytes.NewBuffer, json.Indent, json.Marshal, jsonparser.Get, require.Equal, require.NoError, require.True.

TestGraphQLConfigAdapter_EngineConfigV2

References: apidef.APIDefinition, apidef.GraphQLConfig, assert.Equal, assert.Error, assert.NoError, json.Unmarshal, require.NoError, testing.T.

TestGraphQLConfigAdapter_OpenAPI

References: apidef.GraphQLExecutionModeExecutionEngine, bytes.NewBuffer, json.Indent, json.Marshal, jsonparser.Get, require.Equal, require.NoError, require.True.

TestGraphqlEngineAdapterTypeFromApiDefinition

References: apidef.APIDefinition, apidef.GraphQLConfig, apidef.GraphQLExecutionMode, apidef.GraphQLExecutionModeExecutionEngine, apidef.GraphQLExecutionModeProxyOnly, apidef.GraphQLExecutionModeSubgraph, apidef.GraphQLExecutionModeSupergraph, assert.Equal, testing.T.

TestIsProxyOnlyAPIDefinition

References: apidef.APIDefinition, apidef.GraphQLConfig, apidef.GraphQLExecutionMode, apidef.GraphQLExecutionModeExecutionEngine, apidef.GraphQLExecutionModeProxyOnly, apidef.GraphQLExecutionModeSubgraph, apidef.GraphQLExecutionModeSupergraph, assert.Equal, testing.T.

TestIsSupergraphAPIDefinition

References: apidef.APIDefinition, apidef.GraphQLConfig, apidef.GraphQLExecutionMode, apidef.GraphQLExecutionModeExecutionEngine, apidef.GraphQLExecutionModeProxyOnly, apidef.GraphQLExecutionModeSubgraph, apidef.GraphQLExecutionModeSupergraph, assert.Equal, testing.T.

TestIsUniversalDataGraphAPIDefinition

References: apidef.APIDefinition, apidef.GraphQLConfig, apidef.GraphQLExecutionMode, apidef.GraphQLExecutionModeExecutionEngine, apidef.GraphQLExecutionModeProxyOnly, apidef.GraphQLExecutionModeSubgraph, apidef.GraphQLExecutionModeSupergraph, assert.Equal, testing.T.