question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RequestHeader for get headers in query

See original GitHub issue

Hi!, I trying to get header user agent and another params.

I try this:

@GraphQLQuery(name = "getByCode")
	public UserDTO getByCode(@GraphQLArgument(name = "code") Date code, @RequestHeader(value="User-Agent") String userAgent) {
		
		
		UserDTO out = new UserDTO();
		return out;
	}

And this:

@GraphQLQuery(name = "getByCode")
	public UserDTO getByCode(@GraphQLArgument(name = "code") Date code, @ServletRequest request) {
		
		
		UserDTO out = new UserDTO();
		return out;
	}

How i can get the headers?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kaqqaocommented, Oct 6, 2018

By default, SPQR Spring Boot Starter will use DefaultGlobalContext which contains the original request, as you have found out.

You can inject the context using @GraphQLRootContext:

public ResponseDTO buscoYOfrezco(
	 @GraphQLArgument(name = "busco") String busco, 
	@GraphQLArgument(name = "ofrezco") String ofrezco,
	@GraphQLRootContext DefaultGlobalContext context) {
...
}

You can also register a custom ArgumentInjector that would recognize Spring annotations like @RequestHeader. Take a look at the context injector for inspiration.

SPRQ Spring module will eventually have this built-in, but it’s easily added manually as well.

1reaction
kaqqaocommented, Mar 5, 2019

@dguduguntla Yes, that would be correct. You can also create a custom ArgumentInjector to use a custom annotation (e.g. @HttpHeader("Authorization")) for the same purpose. Or if you’re using Spring, you can use Spring’s @RequestHeader("Authorization") annotation. Again, this is not built-in (will be soon), but it’s very easy to add yourself. But, since this is about authorization, the best place to implement such concerns is actually in a ResolverInterceptor. See this test for an example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to read header using @Request header in spring-boot ...
1 Answer 1 ... You're right for getting specific headers with @RequestHeader you need to define any of them as new method param...
Read more >
Http.RequestHeader (Play 2.8.x)
Checks if the request has the header. Retrieves a single header. The request id. The query string content.
Read more >
HTTP headers and common query string parameters for JSON
The JSON API uses the following query string parameters: ... A request header that specifies a user project to bill for access charges...
Read more >
HTTP headers - MDN Web Docs - Mozilla
It is a request header that indicates the request's mode to a server. It is a Structured Header whose value is a token...
Read more >
Understanding REST Headers and Parameters - SoapUI
You will have to set the request headers when you are sending the request for testing an API and you will have to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found