graphql-flutter
graphql-flutter copied to clipboard
Unauthorized
Hi
I am trying to add access token but I am not sure what is the right way using this package?
Here is my code. Can someone tell me where the mistake?
First way:
static AuthLink authLink = AuthLink(getToken: () async {
return 'Bearer ${accessToken}';
});
static WebSocketLink realtimeWebsocketLink = WebSocketLink(
'wss://pdns-realtime-app.company.xyz/graphql',
config: SocketClientConfig(
inactivityTimeout: const Duration(seconds: 25),
),
subProtocol: GraphQLProtocol.graphqlTransportWs,
);
static Link realtimeLink = authLink.concat(realtimeWebsocketLink);
final realtimeClient = ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: GraphQLCache(),
link: realtimeLink,
),
);
Second way:
static WebSocketLink realtimeWebsocketLink = WebSocketLink(
'wss://pdns-realtime-app.company.xyz/graphql',
config: SocketClientConfig(
initialPayload: () async {
return {
"headers": {"Authorization": 'Bearer ${accessToken}'},
};
},
inactivityTimeout: const Duration(seconds: 25),
),
subProtocol: GraphQLProtocol.graphqlTransportWs,
);
final realtimeClient = ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: GraphQLCache(),
link: realtimeWebsocketLink,
),
);
Third way:
static AuthLink authLink = AuthLink(getToken: () async {
return 'Bearer ${accessToken}';
});
static WebSocketLink realtimeWebsocketLink = WebSocketLink(
'wss://pdns-realtime-app.company.xyz/graphql',
config: SocketClientConfig(
initialPayload: () async {
return {
"headers": {"Authorization": 'Bearer ${accessToken}'},
};
},
inactivityTimeout: const Duration(seconds: 25),
),
subProtocol: GraphQLProtocol.graphqlTransportWs,
);
static Link realtimeLink = authLink.concat(realtimeWebsocketLink);
final realtimeClient = ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: GraphQLCache(),
link: realtimeLink,
),
);
All of these way not work. I debug the token is reach to all the ways.
Where you are receiving the error, in the was or in the HTTP client?
But in all your example I see a wrong usage of the link, or a usage that I did not know.
I use somethings like
final Link link = Link.split(
(request) => request.isSubscription,
wsLink,
httpLink,
);
closing for lack of reproducible, feel free to reopen it if you find a good example