Search code examples
graphqlgraphql-javanetflixnetflix-dgs

how to get the header info in Netflix DGS resolver


We can write the query resolver layer as below

@DgsData(parentType = "Query", field = "answersByQuestionUuid")
    public List<Answer> answersByQuestionUuid(@InputArgument("questionUuid") UUID questionUuid,
                                              @InputArgument("enhancedContent") boolean enhancedContent,
                                              @InputArgument("templateName") String templateName)  {
        if (enhancedContent) {
            return getStructuredAnswersByQuestionUUID(questionUuid.toString(), templateName);
        }
        return getAnswersByQuestionUUID(questionUuid);
    }

How I can get the HTTP header in the resolver.


Solution

  • In addition to DGS input arguments, you can use the @RequestHeader annotation from the Spring framework to receive HTTP request header values. For example:

        public List<Answer> answersByQuestionUuid(@InputArgument("questionUuid") UUID questionUuid,
                                                  @RequestHeader("Content-Type") String contentType)  {