-
-
Notifications
You must be signed in to change notification settings - Fork 630
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
Need more headers in AuthLink #173
Comments
You can write your own Link: typedef GetHeaders = Future<Map<String, String>> Function();
class CustomAuthLink extends Link {
CustomAuthLink({
this.getHeaders,
}) : super(
request: (Operation operation, [NextLink forward]) {
StreamController<FetchResult> controller;
Future<void> onListen() async {
try {
final Map<String, String> headers = await getHeaders();
operation.setContext(<String, Map<String, String>>{
'headers': headers
});
} catch (error) {
controller.addError(error);
}
await controller.addStream(forward(operation));
await controller.close();
}
controller = StreamController<FetchResult>(onListen: onListen);
return controller.stream;
},
);
GetHeaders getHeaders;
} And then you can implement it just as you would with the Hope that helps! |
Closing, seems revolved. |
@HofmannZ need to reopen this as the above CustomAuthLink's parameter signatures fails for 4.0.0 |
@5hanth we moved to a new link system, see /~https://github.com/zino-app/graphql-flutter/blob/beta/changelog-v3-v4.md#we-now-use-the-gql_link-system |
If people are having a hard time finding an example. /~https://github.com/gql-dart/gql/blob/master/links/gql_link/example/gql_link_example.dart |
You can create your own link (updated answer 2021) :
|
I think the previous solutions are expired and the new link system and the example is not simple to understand and use, so so first I have singleton service has one instance of the client with the default headers
and using the query like this
so the dynamic headers will be added to the default headers in each request also you can add RequestExtensionsThunk,HttpLinkResponseContext,ResponseExtensions to this list. |
Our API service uses access-token and refresh token.
Here just one header: 'Authorization'
/~https://github.com/zino-app/graphql-flutter/blob/next/lib/src/link/auth/link_auth.dart#L21
We need 3 custom named headers.
for example:
Thanks.
The text was updated successfully, but these errors were encountered: