MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / GraphqlHandler

Method GraphqlHandler

internal/http_handlers/graphql.go:217–315  ·  view source on GitHub ↗

GraphqlHandler is the main handler that handles all GraphQL requests.

()

Source from the content-addressed store, hash-verified

215
216// GraphqlHandler is the main handler that handles all GraphQL requests.
217func (h *httpProvider) GraphqlHandler() gin.HandlerFunc {
218 gqlProvider, err := graphql.New(h.Config, &graphql.Dependencies{
219 Log: h.Log,
220 AuditProvider: h.AuditProvider,
221 AuthenticatorProvider: h.AuthenticatorProvider,
222 EmailProvider: h.EmailProvider,
223 EventsProvider: h.EventsProvider,
224 MemoryStoreProvider: h.MemoryStoreProvider,
225 SMSProvider: h.SMSProvider,
226 StorageProvider: h.StorageProvider,
227 TokenProvider: h.TokenProvider,
228 ServiceProvider: h.ServiceProvider,
229 AuthzEngine: h.AuthzEngine,
230 })
231 if err != nil {
232 h.Log.Error().Err(err).Msg("Failed to create graphql provider")
233 return func(c *gin.Context) {
234 c.JSON(http.StatusServiceUnavailable, gin.H{
235 "error": "graphql_unavailable",
236 "error_description": "GraphQL service failed to initialize.",
237 })
238 }
239 }
240
241 // NewExecutableSchema and Config are in the generated.go file
242 // Resolver is in the resolver.go file
243 srv := handler.New(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{
244 GraphQLProvider: gqlProvider,
245 }}))
246
247 srv.AddTransport(transport.Options{})
248 // transport.GET is intentionally omitted: GraphQL queries (and especially
249 // mutations) over GET leak into proxy/server logs and browser history.
250 // Clients must POST.
251 srv.AddTransport(transport.POST{})
252
253 srv.SetQueryCache(lru.New[*ast.QueryDocument](1000))
254 srv.AroundFields(h.gqlCollectResolvedFieldsMiddleware())
255 srv.AroundOperations(h.gqlMetricsMiddleware())
256 if h.Config.EnableGraphQLIntrospection {
257 srv.Use(extension.Introspection{})
258 }
259 srv.Use(extension.AutomaticPersistedQuery{
260 Cache: lru.New[string](100),
261 })
262
263 // Limit query depth, alias count, AND complexity through a single
264 // extension so all three rejections share one Prometheus counter
265 // (authorizer_graphql_limit_rejections_total). Defaults applied if
266 // config is unset.
267 maxComplexity := h.Config.GraphQLMaxComplexity
268 if maxComplexity <= 0 {
269 maxComplexity = 300
270 }
271 maxDepth := h.Config.GraphQLMaxDepth
272 if maxDepth <= 0 {
273 maxDepth = 15
274 }

Callers

nothing calls this directly

Calls 7

gqlMetricsMiddlewareMethod · 0.95
NewFunction · 0.92
NewExecutableSchemaFunction · 0.92
ContextWithGinFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected