Skip to content

Commit

Permalink
Merge pull request #186 from Netflix/spring-graphql-docs
Browse files Browse the repository at this point in the history
Update docs with request/response interceptor.
  • Loading branch information
srinivasankavitha authored Aug 2, 2024
2 parents 91484fd + 2623b6d commit 8dcf44f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
23 changes: 23 additions & 0 deletions docs/advanced/intercepting-http-request-response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Response Instrumentation
The DGS framework internally uses [GraphQL Java] and [Spring for GraphQL].

If you need to modify the HTTP request and response headers, you can leverage the `WebGraphQlInterceptor` in [Spring for GraphQL] (https://docs.spring.io/spring-graphql/reference/transports.html#server.interception) to accomplish this.
This provides a hook to update the request and response headers based using the `GraphQLContext`

#### Example:

```java
@Component
public class MyInterceptor implements WebGraphQlInterceptor {
@Override
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
String value = request.getHeaders().getFirst("myHeader");
request.configureExecutionInput((executionInput, builder) ->
builder.graphQLContext(Collections.singletonMap("myHeader", value)).build());
return chain.next(request).doOnNext((response) -> {
String value = response.getExecutionInput().getGraphQLContext().get("myContext");
response.getResponseHeaders().add("MyContext", value);
});
}
}
```
33 changes: 0 additions & 33 deletions docs/advanced/response-instrumentation.md

This file was deleted.

5 changes: 5 additions & 0 deletions docs/spring-graphql-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ You can turn on async behavior by setting the `dgs.graphql.spring.webmvc.asyncdi
It is worth noting that with the Spring GraphQL integration, your MockMVC test set up does need to be updated.
Since web request processing is now based on async dispatching mechanism, we now [require explicit handling for this](https://docs.spring.io/spring-framework/reference/testing/spring-mvc-test-framework/async-requests.html) in the test setup.

### Modifying Response headers
Previously, the DGS Framework offered a mechanism to add custom response headers based on the result of processing the GraphQL query using a special `DgsRestController.DGS_RESPONSE_HEADERS_KEY` key.
This is no longer supported.
The recommended way forward is to use the `WebGraphQlInterceptor` in Spring for GraphQL as described [here](./advanced/intercepting-http-request-response.md))

## Known Gaps and Limitations
At this time, we are lacking support for SSE based subscriptions which is available in the original DGS Framework.
This is on the roadmap and will be made available in the near future depending on support in spring-graphql.
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ nav:
- Subscriptions: advanced/subscriptions.md
- Interfaces and Unions: advanced/type-resolvers-for-abstract-types.md
- Instrumentation (Tracing, Metrics): advanced/instrumentation.md
- Response Instrumentation for MVC: advanced/response-instrumentation.md
- Intercepting Http request and Response for MVC: advanced/intercepting-http-request-response.md
- GraphQLContext : advanced/graphqlcontext-leveraging.md
- Data Fetching Context: advanced/custom-datafetcher-context.md
- Federated Testing: advanced/federated-testing.md
Expand Down

0 comments on commit 8dcf44f

Please sign in to comment.