gql-dart / ferry

Stream-based strongly typed GraphQL client for Dart
https://ferrygraphql.com/
MIT License
593 stars 113 forks source link

[Question] Is there a way to pass specific headers per request? #556

Open Pacane opened 7 months ago

Pacane commented 7 months ago

Hi,

I'd like to be able to pass specific headers on a per request base. I know I can do this by re-creating a client using another HttpLink with the headers I want to pass, but is there a way to do this with an existing client?

I used to use Artemis and we could pass in the Context on execute, which allowed me to override the headers in the request. Is there such a feature within Ferry?

knaeckeKami commented 7 months ago

Ferry does not currently support this on a per request basis directly, but you can add a Link() in front of your HttpLink() that adds the Context entities (ferry used the same system as Artemis under the hood for this).

You could also have the custom link add the headers conditionally, e.g. only for specific requests.

An example link this handles authentication via headers is here: https://github.com/gql-dart/gql/blob/master/examples/gql_example_http_auth_link/lib/http_auth_link.dart

tpucci commented 5 months ago

Hello there 👋 I am interested in passing a Context. How can we add ContextEntries to requests @knaeckeKami ?

tpucci commented 5 months ago

I think it can not be done because ferry generated code is:

  @override
  Request get execRequest => Request(
    operation: operation,
    variables: vars.toJson(),
  );

...which can not be passed a context 😅 I'll opened a feature request.