What would be the best method of gaining access to the HttpRequest object of the current request in my query. I have some code like this
```
public class Query
{
public async Task<IEnumerable<Address>> AddressAccess()
{
var addresses = new[]
{
new Address
{
AddressId = "Test"
}
};
return addresses;
}
}
```
Normally in a web api i would just use Request.Headers, i need this object so i can pass some extra data from the headers into my query
There are two ways to do it.
Write a request interceptor and copy the needed headers into the context data. This will keep your graphql layer clean from http types and lets you write simpler tests.
Use IHttpContextAccessor in your resolver.
I will post some code later today
@michaelstaib Point #2 worked great thank you!
For anyone following this issue my code now looks like:
```
public class Query
{
private IHttpContextAccessor _contextAccessor;
public Query(HttpContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}
public async Task<IEnumerable<Address>> AddressAccess()
{
//Use _contextAccessor here
return new Address[]
{
new Address(),
};
}
}
```
Most helpful comment
@michaelstaib Point #2 worked great thank you!
For anyone following this issue my code now looks like:
```
public class Query
{
private IHttpContextAccessor _contextAccessor;
```