override fun intercept()

in graphql-dgs-spring-graphql/src/main/kotlin/com/netflix/graphql/dgs/springgraphql/webmvc/DgsWebMvcGraphQLInterceptor.kt [40:87]


    override fun intercept(
        request: WebGraphQlRequest,
        chain: WebGraphQlInterceptor.Chain,
    ): Mono<WebGraphQlResponse> {
        // We need to pass in the original server request for the dgs context
        val servletRequestAttributes =
            if (RequestContextHolder.getRequestAttributes() is ServletRequestAttributes) {
                (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes)
            } else {
                null
            }

        val dgsContext =
            if (servletRequestAttributes != null) {
                val webRequest: WebRequest = ServletWebRequest(servletRequestAttributes.request, servletRequestAttributes.response)
                dgsContextBuilder.build(DgsWebMvcRequestData(request.extensions, request.headers, webRequest))
            } else {
                dgsContextBuilder.build(DgsWebMvcRequestData(request.extensions, request.headers))
            }

        var dataLoaderRegistry: DataLoaderRegistry? = null
        request.configureExecutionInput { e, builder ->

            dataLoaderRegistry =
                dgsDataLoaderProvider.buildRegistryWithContextSupplier { e.graphQLContext }

            builder
                .context(dgsContext)
                .graphQLContext(dgsContext)
                .dataLoaderRegistry(dataLoaderRegistry)
                .build()
        }

        return if (dgsSpringConfigurationProperties.webmvc.asyncdispatch.enabled) {
            chain.next(request).doFinally {
                if (dataLoaderRegistry is AutoCloseable) {
                    (dataLoaderRegistry as AutoCloseable).close()
                }
            }
        } else {
            @Suppress("BlockingMethodInNonBlockingContext")
            val response = chain.next(request).block()!!
            if (dataLoaderRegistry is AutoCloseable) {
                (dataLoaderRegistry as AutoCloseable).close()
            }
            return Mono.just(response)
        }
    }