@DgsMutation
public CompletableFuture<CreateResponse> createAttachment(@InputArgument(REQUEST) @Valid @NotNull AttachmentCreateRequest attachment,
@RequestHeader(name = "EVENT_ID") String header) {
return attachmentService.createAttachment(attachment)
.contextWrite(context -> context.put("EVENT_ID", header))
.toFuture();
}
Integration Test Case
@ActiveProfiles(resolver = IntegrationTestActiveProfileResolver.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
class AttachmentQueriesIntegrationTest {
@Autowired
private GraphQLTestTemplate graphQLTestTemplate;
@Test
void testShouldCreateAttachment() throws IOException {
graphQLTestTemplate.withAdditionalHeader("EVENT_ID", "event011");
GraphQLResponse response = graphQLTestTemplate.postForResource("graphql/test-create-attachment.graphql");
assertNotNull(response);
assertTrue(response.isOk());
CreateResponse result = response.get("$.data.createAttachment", CreateResponse.class);
assertNotNull(result.getEntityId());
assertNotNull(result.getTimestamp());
}
2022-10-06 14:36:56.043 WARN 7112 --- [ graphql-exec-1] n.g.e.SimpleDataFetcherExceptionHandler : Exception while fetching data (/createAttachment) : graphQLContext[GraphQLContextKey.DGS_CONTEXT_KEY] must not be null
java.lang.NullPointerException: graphQLContext[GraphQLContextKey.DGS_CONTEXT_KEY] must not be null