Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pacane opened this issue Dec 2, 2023 · 3 comments
Open

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

Pacane opened this issue Dec 2, 2023 · 3 comments

Comments

@Pacane
Copy link

Pacane commented Dec 2, 2023

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
Copy link
Collaborator

knaeckeKami commented Dec 2, 2023

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
Copy link
Contributor

tpucci commented Feb 1, 2024

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

@tpucci
Copy link
Contributor

tpucci commented Feb 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants