I’m using Tyk with a supergraph and a single subgraph setting.
Here is my simplified GraphQL schema:
schema {
query: Query
mutation: Mutation
}
type Query {
getString: String
}
type Mutation {
myMutation(input: MyMutationInput!): MyMutationPayload!
}
input MyMutationInput {
status: String
}
union MyMutationPayload = MyMutationResult | MyMutationErrors
type MyMutationResult {
status: String
}
type MyMutationErrors {
errors: [MyMutationError!]!
}
union MyMutationError = NullArgumentError | EmptyArgumentError
type NullArgumentError implements UserError {
path: [String!]
}
type EmptyArgumentError implements UserError {
path: [String!]
}
interface UserError {
path: [String!]
}
When running the following GraphQL query:
mutation {
myMutation(
input: {
status: "a"
}
) {
...on MyMutationResult {
status
}
...on MyMutationErrors {
errors {
...on UserError {
__typename
}
}
}
}
}
Tyk fails with a runtime error:
2022/07/08 18:35:36 http: panic serving 172.28.0.1:43778: runtime error: index out of range [4] with length 4
goroutine 2262 [running]:
net/http.(*conn).serve.func1(0xc0003cc5a0)
/usr/local/go/src/net/http/server.go:1801 +0x147
panic(0x23a64c0, 0xc000793080)
/usr/local/go/src/runtime/panic.go:975 +0x47a
github.com/jensneuse/graphql-go-tools/pkg/ast.(*Document).AddSelection(...)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/ast/ast_selection.go:139
github.com/jensneuse/graphql-go-tools/pkg/engine/datasource/graphql_datasource.(*Planner).EnterInlineFragment(0xc00000c780, 0x1)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/engine/datasource/graphql_datasource/graphql_datasource.go:386 +0xc45
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkInlineFragment(0xc0009c7500, 0x1)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:2004 +0x165
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkSelectionSet(0xc0009c7500, 0x2)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1719 +0x395
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkField(0xc0009c7500, 0x2)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1809 +0x645
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkSelectionSet(0xc0009c7500, 0x3)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1715 +0x419
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkInlineFragment(0xc0009c7500, 0x2)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:2033 +0x55d
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkSelectionSet(0xc0009c7500, 0x4)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1719 +0x395
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkField(0xc0009c7500, 0x3)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1809 +0x645
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkSelectionSet(0xc0009c7500, 0x5)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1715 +0x419
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walkOperationDefinition(0xc0009c7500, 0x0)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1588 +0x471
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).walk(0xc0009c7500)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1475 +0x5f5
github.com/jensneuse/graphql-go-tools/pkg/astvisitor.(*Walker).Walk(0xc0009c7500, 0xc000ed8038, 0xc00096ca30, 0xc000617650)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/astvisitor/visitor.go:1301 +0xa5
github.com/jensneuse/graphql-go-tools/pkg/engine/plan.(*Planner).Plan(0xc000838cf0, 0xc000ed8038, 0xc00096ca30, 0x0, 0x0, 0xc000617650, 0x0, 0x7fbc6051b4b0)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/engine/plan/plan.go:315 +0xb2d
github.com/jensneuse/graphql-go-tools/pkg/graphql.(*ExecutionEngineV2).getCachedPlan(0xc000845790, 0xc0001705c0, 0xc000ed8038, 0xc00096ca30, 0x0, 0x0, 0xc000617650, 0x0, 0x0)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/graphql/execution_engine_v2.go:295 +0x37e
github.com/jensneuse/graphql-go-tools/pkg/graphql.(*ExecutionEngineV2).Execute(0xc000845790, 0x28071e0, 0xc0000420c8, 0xc000ed8000, 0x27e80a0, 0xc000170590, 0xc0005a67c8, 0x2, 0x2, 0x0, ...)
/go/src/github.com/jensneuse/graphql-go-tools/pkg/graphql/execution_engine_v2.go:257 +0x248
github.com/TykTechnologies/tyk/gateway.(*ReverseProxy).handoverRequestToGraphQLExecutionEngine(0xc00073e780, 0xc000020800, 0xc000ed8000, 0xc000126600, 0x20f0fcf000000000, 0x62c878f8, 0xc0005a6840, 0xee3866)
/go/src/github.com/TykTechnologies/tyk/gateway/reverse_proxy.go:1030 +0x465
github.com/TykTechnologies/tyk/gateway.(*ReverseProxy).handleGraphQL(0xc00073e780, 0xc000020800, 0xc000126600, 0x2800420, 0xc00041b6c0, 0x0, 0x0, 0x0, 0x0)
/go/src/github.com/TykTechnologies/tyk/gateway/reverse_proxy.go:966 +0x2a5
github.com/TykTechnologies/tyk/gateway.(*ReverseProxy).handleOutboundRequest(0xc00073e780, 0xc000020800, 0xc000126600, 0x2800420, 0xc00041b6c0, 0x0, 0xc000170500, 0x13195f, 0x0, 0x0)
/go/src/github.com/TykTechnologies/tyk/gateway/reverse_proxy.go:921 +0x105
github.com/TykTechnologies/tyk/gateway.(*ReverseProxy).WrappedServeHTTP(0xc00073e780, 0x2800420, 0xc00041b6c0, 0xc000126300, 0x0, 0x0, 0x0)
/go/src/github.com/TykTechnologies/tyk/gateway/reverse_proxy.go:1265 +0x200a
github.com/TykTechnologies/tyk/gateway.(*ReverseProxy).ServeHTTP(0xc00073e780, 0x2800420, 0xc00041b6c0, 0xc000126300, 0x19, 0x0)
/go/src/github.com/TykTechnologies/tyk/gateway/reverse_proxy.go:497 +0x24e
github.com/TykTechnologies/tyk/gateway.(*SuccessHandler).ServeHTTP(0xc0008f4e10, 0x2800420, 0xc00041b6c0, 0xc000126300, 0x0)
/go/src/github.com/TykTechnologies/tyk/gateway/handler_success.go:325 +0x2bd
github.com/TykTechnologies/tyk/gateway.(*DummyProxyHandler).ServeHTTP(0xc0008f4e10, 0x2800420, 0xc00041b6c0, 0xc000126300)
/go/src/github.com/TykTechnologies/tyk/gateway/api_loader.go:608 +0x8f3
github.com/TykTechnologies/tyk/gateway.(*Gateway).createMiddleware.func1.1(0x2800420, 0xc00041b6c0, 0xc000126300)
/go/src/github.com/TykTechnologies/tyk/gateway/middleware.go:165 +0xf9c
net/http.HandlerFunc.ServeHTTP(0xc000332500, 0x2800420, 0xc00041b6c0, 0xc000126300)
/usr/local/go/src/net/http/server.go:2042 +0x44
github.com/TykTechnologies/tyk/gateway.(*Gateway).createMiddleware.func1.1(0x2800420, 0xc00041b6c0, 0xc000126300)
/go/src/github.com/TykTechnologies/tyk/gateway/middleware.go:165 +0xf9c
net/http.HandlerFunc.ServeHTTP(0xc000332550, 0x2800420, 0xc00041b6c0, 0xc000126300)
/usr/local/go/src/net/http/server.go:2042 +0x44
github.com/TykTechnologies/tyk/gateway.(*Gateway).createMiddleware.func1.1(0x2800420, 0xc00041b6c0, 0xc000126300)
/go/src/github.com/TykTechnologies/tyk/gateway/middleware.go:165 +0xf9c
net/http.HandlerFunc.ServeHTTP(0xc0003325a0, 0x2800420, 0xc00041b6c0, 0xc000126300)
/usr/local/go/src/net/http/server.go:2042 +0x44
github.com/rs/cors.(*Cors).Handler.func1(0x2800420, 0xc00041b6c0, 0xc000126300)
/go/src/github.com/rs/cors/cors.go:219 +0x1b9
net/http.HandlerFunc.ServeHTTP(0xc0007840c0, 0x2800420, 0xc00041b6c0, 0xc000126300)
/usr/local/go/src/net/http/server.go:2042 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000618240, 0x2800420, 0xc00041b6c0, 0xc000126100)
/go/src/github.com/gorilla/mux/mux.go:210 +0xd3
github.com/TykTechnologies/tyk/gateway.(*handleWrapper).ServeHTTP(0xc0007502d8, 0x2800420, 0xc00041b6c0, 0xc000126100)
/go/src/github.com/TykTechnologies/tyk/gateway/proxy_muxer.go:54 +0x16b
golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP(0x27d22a0, 0xc0007502d8, 0xc000304600, 0x2800420, 0xc00041b6c0, 0xc000126100)
/go/src/golang.org/x/net/http2/h2c/h2c.go:104 +0x437
github.com/TykTechnologies/tyk/gateway.(*h2cWrapper).ServeHTTP(0xc0000228a0, 0x2800420, 0xc00041b6c0, 0xc000126100)
/go/src/github.com/TykTechnologies/tyk/gateway/proxy_muxer.go:42 +0x52
net/http.serverHandler.ServeHTTP(0xc00079ed20, 0x2800420, 0xc00041b6c0, 0xc000126100)
/usr/local/go/src/net/http/server.go:2843 +0xa3
net/http.(*conn).serve(0xc0003cc5a0, 0x28071a0, 0xc00009c280)
/usr/local/go/src/net/http/server.go:1925 +0x8ad
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2969 +0x36c
Here is a demo project illustrating the problem: GitHub - andrey-nakin/tyk-issues
One can find all the Tyk configuration there.